Skip to content

Support @MappedCollection map key is embedded #2054

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
DreamStar92 opened this issue May 14, 2025 · 5 comments
Open

Support @MappedCollection map key is embedded #2054

DreamStar92 opened this issue May 14, 2025 · 5 comments
Labels
type: enhancement A general enhancement

Comments

@DreamStar92
Copy link

DreamStar92 commented May 14, 2025

This is a relevant feature of composite ID.

The key of the Map type should be the composite id (embedded) when the subentity collection references the aggregate root with the composite id.

@schauder
Copy link
Contributor

The key of a mapped collection is completely independent from the id of the parent entity.

Do you mean the idColumn? That indeed isn't addressed yet in #1957

@DreamStar92
Copy link
Author

That's right, it means that both idColumn and keyColumn need to have this capability.

keyColumn should also be supported in the design. When a child entity of an aggregate root uses a map, the key is always the id of the other aggregate root. If the ID of the aggregate root referenced by the ID is a composite ID, then it means that the key of the map should also be a composite ID (embedded).

@schauder
Copy link
Contributor

When a child entity of an aggregate root uses a map, the key is always the id of the other aggregate root.

That is wrong. The key is always the key of the Map or the index of the List.
It is completely 100% independent of the owning entity or its parents

@schauder schauder added type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged labels May 14, 2025
@DreamStar92
Copy link
Author

DreamStar92 commented May 14, 2025

Maybe it's something wrong with my description or I've abused this feature.

Let me give you a simple example.

This is expected.

    record GoodsId(
            int type, String code
    ) {

    }

    record Goods(
            @Id @Embedded.Nullable GoodsId id,
            String name
    ) {

    }

    record Order(
            @Id long id,
            @MappedCollection(idColumn = "order_id", keyColumn = "type+code") Map<GoodsId, OrderItem> itemMap
    ) {

    }

    record OrderItem(
            @Embedded.Empty GoodsId id,
            int quantity
    ) {

    }

After this, I will try AI translation, hoping to reduce errors in expression.

@schauder
Copy link
Contributor

Oh, I see. You want to use the id of an entity as the key in a Map.

Interesting, but valid I guess.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

3 participants