aspose file tools*
The moose likes Object Relational Mapping and the fly likes Question about element collections and relationships described as maps Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Question about element collections and relationships described as maps" Watch "Question about element collections and relationships described as maps" New topic
Author

Question about element collections and relationships described as maps

Jayr Motta
Ranch Hand

Joined: Jul 30, 2010
Posts: 110

When the value type of the map is an entity, a join table is used to map the map for a many-to-many relationship or, by default, for a one-to-many unidirectional relationship. If the relationship is a bidirectional one-to-many/many-to-one relationship, by default the map is mapped in the table of the entity that is the value of the map.


I've read this on the Enthuware Test Studio, 1st exam, as the explanation of the question:

You are modeling a relationship between Customer and CreditCard entities where a Customer can have many CreditCards but a CreditCard belongs to only one Customer. Further, you allow the users to associate a name with each credit card that they have. You have decided to use a Map to store the credit cards in Customer entity, where the key is the name and value is CreditCard entity.

Which of the following options correctly defines creditCards field in Customer class?


My doubt is, what the explanation meant with:

If the relationship is a bidirectional one-to-many/many-to-one relationship, by default the map is mapped in the table of the entity that is the value of the map.


This "element collection and mapping relationships to collection types such as Map's" subject is extremely confusing and boring and neither in the Pro Master JPA 2 nor in the simulates are well explained, I'll read this section of the specification and try to really understand it, but until now it's hard.


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
This means if you have a OneToMany relationship with a ManyToOne back, then you have no join table, just the parent and child tables. The Map key column(s) will be stored in the child table.

See,

http://en.wikibooks.org/wiki/Java_Persistence/Relationships#Example_of_a_map_key_column_relationship_database

TopLink : EclipseLink : Book:Java Persistence : Blog:Java Persistence Performance
 
wood burning stoves
 
subject: Question about element collections and relationships described as maps