Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Extension Attributes- @VirtualAccessMethods
Extension Attributes- @VirtualAccessMethods [message #777724] Tue, 10 January 2012 23:25 Go to next message
Breako Missing name is currently offline Breako Missing nameFriend
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!
Re: Extension Attributes- @VirtualAccessMethods [message #778184 is a reply to message #777724] Wed, 11 January 2012 14:36 Go to previous messageGo to next message
Chris Delahunt is currently offline Chris DelahuntFriend
Messages: 1389
Registered: July 2009
Senior Member
The accessor methods are missing and null because you have not specified that this mapping should use virtual access - it thinks it is a regular mapping.
I believe the example is missing access="VIRTUAL" from the basic mapping:


<basic name="thebirthplace" access="VIRTUAL" attribute-type="String">
<column name="birthplace"/>
<access-methods get-method="get" set-method="set"/>
</basic>


Please try this and let me know if it works, and I will update the example page.

Best Regards,
Chris
Re: Extension Attributes- @VirtualAccessMethods [message #778208 is a reply to message #778184] Wed, 11 January 2012 16:43 Go to previous messageGo to next message
Chris Delahunt is currently offline Chris DelahuntFriend
Messages: 1389
Registered: July 2009
Senior Member
After duplicating the exception and verifying specifying access="VIRTUAL" is required, I've fixed the example at
http://wiki.eclipse.org/EclipseLink/UserGuide/JPA/Advanced_JPA_Development/Extensible_Entities
and the design docs at
http://wiki.eclipse.org/EclipseLink/DesignDocs/340192

Please file a bug if the incorrect example is shown elsewhere.

Best Regards,
Chris
Re: Extension Attributes- @VirtualAccessMethods [message #778452 is a reply to message #778184] Wed, 11 January 2012 16:43 Go to previous messageGo to next message
Chris Delahunt is currently offline Chris DelahuntFriend
Messages: 1389
Registered: July 2009
Senior Member
After duplicating the exception and verifying specifying access="VIRTUAL" is required, I've fixed the example at
http://wiki.eclipse.org/EclipseLink/UserGuide/JPA/Advanced_JPA_Development/Extensible_Entities
and the design docs at
http://wiki.eclipse.org/EclipseLink/DesignDocs/340192

Please file a bug if the incorrect example is shown elsewhere.

Best Regards,
Chris
Re: Extension Attributes- @VirtualAccessMethods [message #779847 is a reply to message #777724] Mon, 16 January 2012 16:49 Go to previous message
James Sutherland is currently offline James SutherlandFriend
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

You are missing access="VIRTUAL",

i.e.
<basic name="thebirthplace" access="VIRTUAL" attribute-type="String">

But please log a bug for the null-pointer, you should get a better error message.


--
James : http://wiki.eclipse.org/EclipseLink : http://en.wikibooks.org/wiki/Java_Persistence : http://java-persistence-performance.blogspot.com/


James : Wiki : Book : Blog : Twitter
Previous Topic:Extension Attributes- @VirtualAccessMethods
Next Topic:Error when trying to use PLSQLTable type as an IN parameter in a PLSQLStoredProcedure in eclipse lin
Goto Forum:
  


Current Time: Sat Nov 09 04:46:38 GMT 2024

Powered by FUDForum. Page generated in 0.02948 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top