About Question enthuware.oce-jpad.v6.1.438 :

All the posts and topics that contain only an error report will be moved here after the error is corrected. This is to ensure that when users view a question in ETS Viewer, the "Discuss" button will not indicate the presence of a discussion that adds no value to the question.

Moderators: Site Manager, fjwalraven

Post Reply
ETS User

About Question enthuware.oce-jpad.v6.1.438 :

Post by ETS User »

An embeddable class may NOT be the key of a map annotated with @ElementCollection.

Can someone point me to the part of specification in 2.5 chapter that says something like this is true? I believe there are no constraints for embeddable class becoming a key in map

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.oce-jpad.v6.1.438 :

Post by admin »

Hello,
This option is a wrong option. So yes, an embeddable class can be the key of a map. The explanation makes it even clearer, "When a map field is annotated with @OneToMany (or @ManyToMany), this means the map value is an Entity. The map key can be a basic type or an embeddable."

HTH,
Paul.
If you like our products and services, please help us by posting your review here.

EricOX
Posts: 1
Joined: Tue Jan 10, 2012 12:18 pm
Contact:

Re: About Question enthuware.oce-jpad.v6.1.438 :

Post by EricOX »

Hello Paul,

I think Paul is asking the option 3 "An embeddable class may NOT be the key of a map annotated with @ElementCollection.". And you are explaining the option 2 "An embeddable class may NOT be the key of a map annotated with @OneToMany.".
I think both option 2 and 3 are not correct.

Thanks

ikotev
Posts: 17
Joined: Sat Feb 28, 2015 2:26 am
Contact:

Re: About Question enthuware.oce-jpad.v6.1.438 :

Post by ikotev »

Hello,
"When a map field is annotated with @OneToMany (or @ManyToMany), this means the map value is an Entity. The map key can be a basic type or an embeddable."
I guess map key can also be an Entity as well right ?

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.oce-jpad.v6.1.438 :

Post by admin »

kotev_@abv.bg wrote:Hello,
"When a map field is annotated with @OneToMany (or @ManyToMany), this means the map value is an Entity. The map key can be a basic type or an embeddable."
I guess map key can also be an Entity as well right ?
No, if you have an entity as map key, then you are basically trying to create a relationship between 3 entities at the same time (because your map value is an entity as well). But the annotation @OneToMany is for relationship between two entities only.

HTH,
Paul.
If you like our products and services, please help us by posting your review here.

ikotev
Posts: 17
Joined: Sat Feb 28, 2015 2:26 am
Contact:

Re: About Question enthuware.oce-jpad.v6.1.438 :

Post by ikotev »

Hi Paul,

Exactly. With Map you made relationship between three entities. To my understanding this is correct. I have the following mapping in Department entity:

@OneToMany(mappedBy = "department")
Map<Office, Employee> employees;

On Employee side:

@ManyToOne
Department department

As a result through department field I can queue employees map by office key.

In specification "2.7 Map Collections" is written that:
The map key and the map value independently can each be a basic type, an embeddable class, or an entity.
9 possible map types are available and one of them is Map<Entity, Entity>.

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.oce-jpad.v6.1.438 :

Post by admin »

Yes, you are right. I have updated the explanation. It still remains an incorrect option though.
thank you for your feedback!
Paul.
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: No registered users and 18 guests