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.
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?
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.
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: