Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Question about element collections and relationships described as maps

 
Ranch Hand
Posts: 110
Google Web Toolkit Java Google App Engine
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
 
Ranch Hand
Posts: 553
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    Bookmark Topic Watch Topic
  • New Topic