This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes JPA Certification (OCEJPA) and the fly likes Element collections and Map relationships Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » JPA Certification (OCEJPA)
Bookmark "Element collections and Map relationships" Watch "Element collections and Map relationships" New topic
Author

Element collections and Map relationships

Jayr Motta
Ranch Hand

Joined: Jul 30, 2010
Posts: 110

Hi,

I'm studying for the JPA certification and while reading a book I encountered the following:

If instead of a many-to-many relationship we had an @ElementCollection of some embeddable type in a Map, we would have to differentiate between the key and the value. We would do this by prefixing the attribute name with "key." or "value.", depending upon which of the embeddable types we were overriding. An element collection of embedded EmployeeInfo types, with the same key overrides as those in the relationship in Listing 5-17, would use the key prefixes:




But I could not understand how a relationship with a real entity could be replaced by this kind of relationship with embeddable types id there is no information about any collection table or any table within the embeddable. I'm kind confused about element collections, I don't know if it's the book that I've bought but it sounds weird sometimes. Does anyone know what the quote above could mean?


Feel free to ask me anything!
www.BlackBeltFactory.com/ui#!/ref=jmotta, SCJP 6, OCWCD JEE5, OCE EJB JEE6
James Sutherland
Ranch Hand

Joined: Oct 01, 2007
Posts: 553
I don't think this is saying you could replace a ManyToMany with an ElementCollection, it is just saying if you had an ElementCollection instead of the a ManyToMany (from the previous example).

It is trying to convey (only) that if an ElementCollection has both a key and a value that is an Embeddable, then the AttributeOverride is ambiguous, does it apply to the key or the value?
So, it is saying that if you had this (odd) situation, you would use the "key" prefix to override the key, and "value." apply to the value. Actually this is news to me, I assume it is defined this way in the Spec though if this book mentions it.

TopLink : EclipseLink : Book:Java Persistence : Blog:Java Persistence Performance
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Element collections and Map relationships
 
Similar Threads
Question about element collections and relationships described as maps
Hibernate mapping collection of primitives
JPA mapping with inheritance, elementcollection and many-to-many relationship
Polymorphism and relationships - JPA
problem with @ManyToMany using MapKeyClass