Difficulties Displaying Hibernated Maps Using JPA Annotations

Perhaps something fundamental I do not understand about the semantics of the JPA @MapKey element. I am trying to save a map with entity keys and entity values. The circuit is automatically generated by sleep mode. It generates a connection table that maps value objects to the containing object (which has the Map property) and ignores the keys. so effectively, he simply sees it as a set of values ​​and ignores the keys, as far as I can tell. What am I missing here? thank you

@Entity public class PracticeMap { @javax.persistence.OneToMany(cascade = CascadeType.ALL) @javax.persistence.MapKey public Map<KeySample, ValueSample> getMap1() { return map1; } //more unrelated/standard bits here } 
+4
source share
1 answer

Take a look at javadoc @MapKey - it is used when you need to treat certain fields of a value object as keys.

If your key and value must be different objects, you need to use @MapKeyJoinColumn (introduced in JPA 2.0).

+2
source

All Articles