Community
Participate
Working Groups
At the moment, you need to specify the table name when using a map that uses a join table Given: @Entity public class EnumKeyHolder { @GeneratedValue @Id private int id; @OneToMany( cascade=CascadeType.ALL ) @MapKeyEnumerated(EnumType.STRING) @MapKeyColumn(name="mymapkeycolulmn") Map<MyEnum,EnumKeyProperty> properties = new HashMap<MyEnum,EnumKeyProperty>(); ... And public enum MyEnum{ VALUE1( "value1" ), // default VALUE2( "value2" ) ... @Entity public class EnumKeyProperty { @Id private int myKey; private int myValue; The following code will not put a value in the table for the map key: public static void main(String[] args) { EntityManagerFactory emf = Persistence.createEntityManagerFactory("TestEnumeratedMapKey"); EntityManager em = emf.createEntityManager(); em.getTransaction().begin(); EnumKeyHolder holder = new EnumKeyHolder(); EnumKeyProperty prop = new EnumKeyProperty(); prop.setMyKey(23); prop.setMyValue(22); holder.getProperties().put(MyEnum.VALUE1, prop); em.persist(holder); em.persist(prop); em.getTransaction().commit(); }
Workaround: Specify the table: @OneToMany( cascade=CascadeType.ALL ) @MapKeyEnumerated(EnumType.STRING) @MapKeyColumn(table="ENUMKEYHOLDER_ENUMKEYPROPERTY", name="mymapkeycolulmn") Map<MyEnum,EnumKeyProperty> properties = new HashMap<MyEnum,EnumKeyProperty>(); Possible fix: OneToManyAccessor.processManyToManyMapping() Move the processJoinTable call earlier in the method like this: protected void processManyToManyMapping() { // Create a M-M mapping and process common collection mapping metadata // first followed by specific metadata. ManyToManyMapping mapping = new ManyToManyMapping(); // Process the JoinTable metadata. processJoinTable(mapping, mapping.getRelationTableMechanism(), getJoinTableMetadata()); process(mapping); // 266912: If this 1:n accessor is different than the n:n mapping - track this mapping.setDefinedAsOneToManyMapping(true); }
Setting target and priority. See the following page for the meanings of these fields: http://wiki.eclipse.org/EclipseLink/Development/Bugs/Guidelines Community: Please vote for this bug if it is important to you. Votes are one of the main criteria we use to determine which bugs to fix next.
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink