Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Extension Attributes- @VirtualAccessMethods(Problem with extension attributes.)
Extension Attributes- @VirtualAccessMethods [message #777722] Tue, 10 January 2012 23:25 Go to next message
Breako Missing name is currently offline 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 instructions.

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 #779842 is a reply to message #777722] Mon, 16 January 2012 16:49 Go to previous message
James Sutherland is currently offline James Sutherland
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 : Wiki : Book : Blog : Twitter
Previous Topic:Problems retrieving a joined entity object
Next Topic:Extension Attributes- @VirtualAccessMethods
Goto Forum:
  


Current Time: Wed Oct 01 04:16:46 GMT 2014

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

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