About Question enthuware.oce-jpad.v6.1.434 :
Moderator: admin
-
- Posts: 28
- Joined: Fri Jan 02, 2015 12:13 pm
- Contact:
About Question enthuware.oce-jpad.v6.1.434 :
Are the keys of a Map persist when a collection of elements or entity relationships is represented by a java.util.Map? If yes how? Please discuss the possible cases of basic or embeddable valued map or entity valued map when the relationship is many-to-many, unidirectional one-to-many, bidirectional one-to-many/many-to-one.
-
- Site Admin
- Posts: 10078
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.oce-jpad.v6.1.434 :
You will need to go through Chapter 2 of the JPA specification. It explains all the information that you are asking.
HTH,
Paul.
HTH,
Paul.
If you like our products and services, please help us by posting your review here.
-
- Posts: 28
- Joined: Fri Jan 02, 2015 12:13 pm
- Contact:
Re: About Question enthuware.oce-jpad.v6.1.434 :
Yes, I have read the explanation of enthuware.oce-jpad.v6.1.434 labelled as important point and I realized as well that it is filtered and copied from 2.7.2 Map Values of the JPA 2.0 final spec. That's a good approach by the way, I can always dive deeper if necessary. And the best in this approach is that I don't have to struggle through the spec - that is always a pain in the ass - because you did it for me before, filtered it well according to the requirements of the exam and connected specific sections to tricky questions found on the exam through the explanations...
In this case however I was unable to answer my question by myself with the help of the spec. For example:
" 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. "
How do you persist the keys in this case ???? Each row in the entity table is an entity that is one of the values of the map. I could have a column in this table to store the keys for the map ... but the same value can be assigned to several keys in the same map.. so this solution does not seem to work. Maybe we don't have to persist the keys in this case. I am confused, please help.
In this case however I was unable to answer my question by myself with the help of the spec. For example:
" 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. "
How do you persist the keys in this case ???? Each row in the entity table is an entity that is one of the values of the map. I could have a column in this table to store the keys for the map ... but the same value can be assigned to several keys in the same map.. so this solution does not seem to work. Maybe we don't have to persist the keys in this case. I am confused, please help.
-
- Site Admin
- Posts: 10078
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.oce-jpad.v6.1.434 :
You might want to try running the toy app and see how it is persisted. I would do the same before saying anything to make sure what I say is correct.
If you like our products and services, please help us by posting your review here.
-
- Posts: 358
- Joined: Fri Nov 29, 2013 8:26 pm
- Contact:
Re: About Question enthuware.oce-jpad.v6.1.434 :
The question says using the name of the credit card as the key. Since the name of the credit card is not the primary key, the second correct option should have @MapKey (name="nameOfCard") or something like that.
By default , the map key column should be called creditCards_KEY. This column stores the name of the credit card.
By default , the map key column should be called creditCards_KEY. This column stores the name of the credit card.
-
- Posts: 125
- Joined: Thu Jul 05, 2018 6:44 pm
- Contact:
Re: About Question enthuware.oce-jpad.v6.1.434 :
@MapKey is an annotation for specifying only what field in X a Map<String,X> uses for the map's keys.himaiMinh wrote: ↑Thu Jun 29, 2017 8:58 amThe question says using the name of the credit card as the key. Since the name of the credit card is not the primary key, the second correct option should have @MapKey (name="nameOfCard") or something like that.
By default , the map key column should be called creditCards_KEY. This column stores the name of the credit card.
@MapKeyColumn is a physical mapping annotation. It specifies stuff to do with the column in the db. The default name of the column is overridden by the name element.
But yes, if you don't specify @MapKey(name=xxx) on a Map<String,X> then JPA will assume the map is keyed by the pk of X.
-
- Posts: 125
- Joined: Thu Jul 05, 2018 6:44 pm
- Contact:
Re: About Question enthuware.oce-jpad.v6.1.434 :
Is this effectively saying, when you have (in say entity A) a onetomany Map<X,ENTITY> that is unidirectional, this is analogous to having List<ENTITY>, ie that means there is no mapping in ENTITY that maps back to the containing entity (A) so, in the absence of any other annotations on the collection (List/Map/whatever) a join table will be determined as being required?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.
Is this saying that in practice the mapping of a bidirectional Map<X,ENTITY> is by default the same as List<ENTITY>, or something different? I'm not sure what "is mapped" means - I thought "mapping" is a verb that describes where the application developer decides to put his annotations to reflect his ORM, not how JPA interprets those mappings, but now I'm not so sure.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.
Thanks.
Who is online
Users browsing this forum: No registered users and 10 guests