Extension Attributes- @VirtualAccessMethods [message #777724] |
Tue, 10 January 2012 23:25 |
Breako Missing name Messages: 13 Registered: November 2011 |
Junior Member |
|
|
Right just spent the last four hours banging my head against the wall with this one, hopefully someone can help.
I am trying to use the new @VirtualAccessMethods annotation to add some attributes to my POJO. I am trying to follow these http://wiki.eclipse.org/EclipseLink/UserGuide/JPA/Advanced_JPA_Development/Extensible_Entities.
Here is my POJO
@Entity
@VirtualAccessMethods
public class User {
/* Surrogate Key - automatically generated by DB. */
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Id
private int id;
private String name;
@Transient
private Map<String, Object> extensions = new HashMap();
public int getId() {
return id;
}
public void setName(String name) {
this.name=name;
}
public String getName() {
return name;
}
public <T> T get(String name) {
return (T) extensions.get(name);
}
public Object set(String name, Object value) {
return extensions.put(name, value);
}
}
Here is my eclipselink-orm.xml file:
<entity-mappings
xmlns="http://www.eclipse.org/eclipselink/xsds/persistence/orm"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.eclipse.org/eclipselink/xsds/persistence/orm http://www.eclipse.org/eclipselink/xsds/eclipselink_orm_2_1.xsd"
version="2.1">
<entity class="com.opsource.persistence.User">
<attributes>
<basic name="thebirthplace" attribute-type="String">
<column name="birthplace"/>
<access-methods get-method="get" set-method="set"/>
</basic>
</attributes>
</entity>
</entity-mappings>
I update my database appropriately.
Note: I have to instantiate the hashmap in my POJO, otherwise I'd get a null pointer when I try to set birthplace!
When I try to instantiate an EntityManagerFactory, I get this exception...
...
Exception [EclipseLink-30005] (Eclipse Persistence Services - 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.PersistenceUnitLoadingException
Exception Description: An exception was thrown while searching for persistence archives with ClassLoader: sun.misc.Launcher$AppClassLoader@601bb1
Internal Exception: javax.persistence.PersistenceException: Exception [EclipseLink-28018] (Eclipse Persistence Services - 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.EntityManagerSetupException
Exception Description: Predeployment of PersistenceUnit [my-app] failed.
Internal Exception: java.lang.NullPointerException
at org.eclipse.persistence.exceptions.PersistenceUnitLoadingException.exceptionSearchingForPersistenceResources(PersistenceUnitLoadingException.java:127)
at org.eclipse.persistence.jpa.PersistenceProvider.createEntityManagerFactory(PersistenceProvider.java:115)
at javax.persistence.Persistence.createEntityManagerFactory(Unknown Source)
at javax.persistence.Persistence.createEntityManagerFactory(Unknown Source)
at com.opsource.persistence.UserDAOTest$EntityManagerFactoryHolder.<clinit>(UserDAOTest.java:30)
... 26 more
Caused by: javax.persistence.PersistenceException: Exception [EclipseLink-28018] (Eclipse Persistence Services - 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.EntityManagerSetupException
Exception Description: Predeployment of PersistenceUnit [my-app] failed.
Internal Exception: java.lang.NullPointerException
at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.predeploy(EntityManagerSetupImpl.java:1402)
at org.eclipse.persistence.internal.jpa.deployment.JPAInitializer.callPredeploy(JPAInitializer.java:98)
at org.eclipse.persistence.jpa.PersistenceProvider.createEntityManagerFactory(PersistenceProvider.java:105)
... 29 more
Caused by: Exception [EclipseLink-28018] (Eclipse Persistence Services - 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.EntityManagerSetupException
Exception Description: Predeployment of PersistenceUnit [my-app] failed.
Internal Exception: java.lang.NullPointerException
at org.eclipse.persistence.exceptions.EntityManagerSetupException.predeployFailed(EntityManagerSetupException.java:221)
... 32 more
Caused by: java.lang.NullPointerException
at org.eclipse.persistence.internal.jpa.metadata.accessors.classes.ClassAccessor.getAccessibleMethod(ClassAccessor.java:672)
at org.eclipse.persistence.internal.jpa.metadata.accessors.classes.ClassAccessor.addAccessors(ClassAccessor.java:337)
at org.eclipse.persistence.internal.jpa.metadata.accessors.classes.ClassAccessor.preProcess(ClassAccessor.java:1134)
at org.eclipse.persistence.internal.jpa.metadata.accessors.classes.MappedSuperclassAccessor.preProcess(MappedSuperclassAccessor.java:682)
at org.eclipse.persistence.internal.jpa.metadata.accessors.classes.EntityAccessor.preProcess(EntityAccessor.java:554)
at org.eclipse.persistence.internal.jpa.metadata.MetadataProject.processStage1(MetadataProject.java:1608)
at org.eclipse.persistence.internal.jpa.metadata.MetadataProcessor.processORMMetadata(MetadataProcessor.java:531)
at org.eclipse.persistence.internal.jpa.deployment.PersistenceUnitProcessor.processORMetadata(PersistenceUnitProcessor.java:526)
at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.predeploy(EntityManagerSetupImpl.java:1337)
... 31 more
Debugging the Eclipselink code. This method (in class ClassAccessor.java) is where the problem is:
protected MetadataMethod getAccessibleMethod(MappingAccessor accessor) {
if (accessor.hasAccessMethods()) {
MetadataMethod getMethod = getJavaClass().getMethod(accessor.getGetMethodName(), new String[]{});
MetadataMethod setMethod = getJavaClass().getMethod(accessor.getSetMethodName(), Arrays.asList(new String[]{getMethod.getReturnType()}));
getMethod.setSetMethod(setMethod);
return getMethod;
The getMethod variable is null. This is because we don't get a match in the getMethodName() even though we should.
The getMethodName() ends up at this code:
public MetadataMethod getMethod(String name, List<String> arguments, boolean checkSuperClass) {
MetadataMethod method = getMethods().get(name);
while ((method != null) && !method.getParameters().equals(arguments)) {
method = method.getNext();
}
if (checkSuperClass && (method == null) && (getSuperclassName() != null)) {
return getSuperclass().getMethod(name, arguments);
}
return method;
}
The method is initialised but "parameters" never equals "arguments".
The code then sets the method to it's next() but there is no next so it ends up null.
Any help appreciated!
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.02948 seconds