Community
Participate
Working Groups
When mapping a class with a BasicCollection mapping as: @Entity public class Employee { @Id @Column(name = "EMP_ID") private int id; @Column(name = "F_NAME") private String firstName; @Column(name = "L_NAME") private String lastName; @BasicCollection(valueColumn = @Column(name = "RESPONS_DESC")) @CollectionTable(name = "RESPONS") private List<String> responsibilities; The Dali JPA 2.0 model gen generates: @Generated(value="Dali", date="2010-06-06T15:16:16.703-0400") @StaticMetamodel(Employee.class) public class Employee_ { public static volatile SingularAttribute<Employee, Integer> id; public static volatile SingularAttribute<Employee, String> firstName; public static volatile SingularAttribute<Employee, String> lastName; public static volatile SingularAttribute<Employee, List> responsibilities; } When invoking getMetamodel I get the following ValidationException [EL Config]: Connected: jdbc:oracle:thin:@localhost:1521:ORCL User: SCOTT Database: Oracle Version: Oracle Database 11g Release 11.1.0.0.0 - Production Driver: Oracle JDBC driver Version: 11.1.0.6.0-Production [EL Info]: basic-collection-example login successful Exception in thread "main" Local Exception Stack: Exception [EclipseLink-7215] (Eclipse Persistence Services - @VERSION@.@QUALIFIER@): org.eclipse.persistence.exceptions.ValidationException Exception Description: Could not load the field named [responsibilities] on the class [class model.Employee_]. Ensure there is a corresponding field with that name defined on the class. Internal Exception: java.lang.IllegalArgumentException: Can not set static javax.persistence.metamodel.SingularAttribute field model.Employee_.responsibilities to org.eclipse.persistence.internal.jpa.metamodel.ListAttributeImpl at org.eclipse.persistence.exceptions.ValidationException.invalidFieldForClass(ValidationException.java:2611) at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.initializeCanonicalMetamodel(EntityManagerSetupImpl.java:2030) at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.getMetamodel(EntityManagerSetupImpl.java:1998) at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.getMetamodel(EntityManagerFactoryImpl.java:495) at test.Main.main(Main.java:18) Caused by: java.lang.IllegalArgumentException: Can not set static javax.persistence.metamodel.SingularAttribute field model.Employee_.responsibilities to org.eclipse.persistence.internal.jpa.metamodel.ListAttributeImpl at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(Unknown Source) at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(Unknown Source) at sun.reflect.UnsafeQualifiedStaticObjectFieldAccessorImpl.set(Unknown Source) at java.lang.reflect.Field.set(Unknown Source) at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.initializeCanonicalMetamodel(EntityManagerSetupImpl.java:2026) ... 3 more I am not sure if the error is in EclipseLink's support for its own advanced mappings when using the Metamodel or if Dali is incorrectly generating the canonical model.
Created attachment 171224 [details] Reproduction Project Built using latest JavaEE Helios RC
To work-around this issue I disabled Dali's model-gen and changed the SingularAttribute for responsibilities to a ListAttribute as: @Generated(value="Dali", date="2010-06-06T19:10:57.187-0400") @StaticMetamodel(Employee.class) public class Employee_ { public static volatile SingularAttribute<Employee, Integer> id; public static volatile SingularAttribute<Employee, String> firstName; public static volatile SingularAttribute<Employee, String> lastName; public static volatile ListAttribute<Employee, List<String>> responsibilities; } I was unable to get the EclipseLink annottaion processor running on this project to compare generated models. I am assigning this to Dali for now but would like to verify that the ElipseLInk model gen is correct or possibly release note the issue for 2.1.
I figured out my PEBKAC issue with the EL model-gen. Its generated model class does not include the BasicCollection mapping: @Generated("EclipseLink-2.1.0.v20100529-r7411 @ Sun Jun 06 19:18:03 EDT 2010") @StaticMetamodel(Employee.class) public class Employee_ { public static volatile SingularAttribute<Employee, Integer> id; public static volatile SingularAttribute<Employee, String> lastName; public static volatile SingularAttribute<Employee, String> firstName; }
Note that, instead of disabling Dali's metamodel generation, you could simply remove the @Generated annotation on the Employee_ class and Dali will continue to generate all the other classes and leave the Employee_ class untouched. (At least that's the hope. :-) ) Of course, you will need to sync Employee_ manually whenever you change Employee.
I changed the BasicCollection mapping to an ElementCollection mapping to resolve the issue. While this is a minimal impact issue it may be tough to diagnose. Dali incorrectly generates the meta model and EclipseLink throws a cryptic error initializing it. We should reinforce the deprecated mappings and mention a potential issue using them with the JPA 2.0 meta model with Dali.
Doug/Guy, have you opened a corresponding bug against the EclipseLink metamodel generator since it does not generate a metamodel attribute for basic-collection?
Created attachment 172256 [details] proposed patch against head This patch fixes the Dali metamodel generation for BasicCollection and BasicMap in both java and orm.
I just tried this on the EclipseLink metamodel generator (off trunk) and it generates just fine. The EclipseLink metamodel has always be generated against the mappings (returned from metadata processing) so I would be very surprised to see it omit BasicCollection and BasicMap mappings.
checked in to HEAD for inclusion in 2.3.1 maintenance
verified fixed in build wtp-sdk-M-3.2.1-20100717062943