Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » [Fixed] NPE when using LAZY loading on ManyToOne relationship
[Fixed] NPE when using LAZY loading on ManyToOne relationship [message #649113] Mon, 17 January 2011 17:55 Go to next message
Daniel Le Berre is currently offline Daniel Le BerreFriend
Messages: 82
Registered: July 2009
Member
I got the following entities:
@Entity
public class A implements Serializable {

    @Id
    @GeneratedValue
    private long id;

    private String value;

    public String getValue() {
        return value;
    }

    public void setValue(String value) {
        this.value = value;
    }

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

}


and
@Entity
public class B implements Serializable {

    @Id
    @GeneratedValue
    private long id;

    @ManyToOne(fetch = FetchType.LAZY)
    private A a;

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public A getA() {
        return a;
    }

    public void setA(A a) {
        this.a = a;
    }

}


When I deploy those entities, I got the following error:
Local Exception Stack: 
Exception [EclipseLink-60] (Eclipse Persistence Services - 2.1.2.v20101206-r8635): org.eclipse.persistence.exceptions.DescriptorException
Exception Description: The method [_persistence_set_a_vh] or [_persistence_get_a_vh] is not defined in the object [ili.ili4.entities.B].
Internal Exception: java.lang.NoSuchMethodException: ili.ili4.entities.B._persistence_get_a_vh()
Mapping: org.eclipse.persistence.mappings.ManyToOneMapping[a]
Descriptor: RelationalDescriptor(ili.ili4.entities.B --> [DatabaseTable(B)])
	at org.eclipse.persistence.exceptions.DescriptorException.noSuchMethodWhileInitializingAttributesInMethodAccessor(DescriptorException.java:1154)
	at org.eclipse.persistence.internal.descriptors.MethodAttributeAccessor.initializeAttributes(MethodAttributeAccessor.java:175)
	at org.eclipse.persistence.internal.descriptors.MethodAttributeAccessor.initializeAttributes(MethodAttributeAccessor.java:156)
	at org.eclipse.persistence.mappings.DatabaseMapping.preInitialize(DatabaseMapping.java:1241)
	at org.eclipse.persistence.mappings.ForeignReferenceMapping.preInitialize(ForeignReferenceMapping.java:1004)
	at org.eclipse.persistence.mappings.ObjectReferenceMapping.preInitialize(ObjectReferenceMapping.java:925)
	at org.eclipse.persistence.descriptors.ClassDescriptor.preInitialize(ClassDescriptor.java:3360)
	at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.initializeDescriptors(DatabaseSessionImpl.java:429)
	at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.initializeDescriptors(DatabaseSessionImpl.java:406)
	at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.postConnectDatasource(DatabaseSessionImpl.java:666)
	at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.loginAndDetectDatasource(DatabaseSessionImpl.java:615)
	at org.eclipse.persistence.internal.jpa.EntityManagerFactoryProvider.login(EntityManagerFactoryProvider.java:228)
	at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:389)
	at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.getServerSession(EntityManagerFactoryImpl.java:164)
	at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManagerImpl(EntityManagerFactoryImpl.java:221)
	at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:209)
	at ili.ili4.tests.ConsultationTest.setUp(ConsultationTest.java:31)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
	at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:27)
	at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: java.lang.NoSuchMethodException: ili.ili4.entities.B._persistence_get_a_vh()
	at java.lang.Class.getDeclaredMethod(Class.java:1937)
	at org.eclipse.persistence.internal.security.PrivilegedAccessHelper.findMethod(PrivilegedAccessHelper.java:61)
	at org.eclipse.persistence.internal.security.PrivilegedAccessHelper.getMethod(PrivilegedAccessHelper.java:252)
	at org.eclipse.persistence.internal.helper.Helper.getDeclaredMethod(Helper.java:1055)
	at org.eclipse.persistence.internal.descriptors.MethodAttributeAccessor.initializeAttributes(MethodAttributeAccessor.java:168)
	... 38 more

Runtime Exceptions: 
---------------------------------------------------------


java.lang.NullPointerException
	at org.eclipse.persistence.internal.security.PrivilegedAccessHelper.getMethodReturnType(PrivilegedAccessHelper.java:326)
	at org.eclipse.persistence.internal.descriptors.MethodAttributeAccessor.getGetMethodReturnType(MethodAttributeAccessor.java:112)
	at org.eclipse.persistence.mappings.ForeignReferenceMapping.validateBeforeInitialization(ForeignReferenceMapping.java:1709)
	at org.eclipse.persistence.descriptors.ClassDescriptor.validateBeforeInitialization(ClassDescriptor.java:5310)
	at org.eclipse.persistence.descriptors.ClassDescriptor.preInitialize(ClassDescriptor.java:3366)
	at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.initializeDescriptors(DatabaseSessionImpl.java:429)
	at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.initializeDescriptors(DatabaseSessionImpl.java:406)
	at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.postConnectDatasource(DatabaseSessionImpl.java:666)
	at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.loginAndDetectDatasource(DatabaseSessionImpl.java:615)
	at org.eclipse.persistence.internal.jpa.EntityManagerFactoryProvider.login(EntityManagerFactoryProvider.java:228)
	at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:389)
	at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.getServerSession(EntityManagerFactoryImpl.java:164)
	at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManagerImpl(EntityManagerFactoryImpl.java:221)
	at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:209)
	at ili.ili4.tests.ConsultationTest.setUp(ConsultationTest.java:31)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
	at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:27)
	at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)


I an not sure if it is a bug in EclipseLink or if I made a mistake in my entities declarations.

[Updated on: Thu, 20 January 2011 22:29]

Report message to a moderator

Re: NPE when using LAZY loading on ManyToOne relationship [message #649506 is a reply to message #649113] Wed, 19 January 2011 14:10 Go to previous messageGo to next message
Chris Delahunt is currently offline Chris DelahuntFriend
Messages: 1389
Registered: July 2009
Senior Member
Hello,

Using a java agent or static weaving to enhance the entity byte code is required to support lazy relationships on OneToOne type mappings, but it looks like it hasn't run.

Please see
http://wiki.eclipse.org/Using_EclipseLink_JPA_Extensions_(ELUG)#Using_EclipseLink_JPA_Weaving
for information on how to setup the java agent to weave your classes, or you can set your OneToOne and ManyToOne relationships to be eager (the default).

Best Regards,
Chris
Re: NPE when using LAZY loading on ManyToOne relationship [message #649541 is a reply to message #649506] Wed, 19 January 2011 16:02 Go to previous messageGo to next message
Daniel Le Berre is currently offline Daniel Le BerreFriend
Messages: 82
Registered: July 2009
Member
I use static weaving in my app, by declaring the eclipselink.weaving property to static in my persistence.xml file.

I use EclipseLink and JPA that way since release 1.0 of EclipseLink.

I guess we are hitting a bug here. Declared here:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=334807

[Updated on: Wed, 19 January 2011 16:23]

Report message to a moderator

Re: NPE when using LAZY loading on ManyToOne relationship [message #649742 is a reply to message #649541] Thu, 20 January 2011 13:56 Go to previous messageGo to next message
Chris Delahunt is currently offline Chris DelahuntFriend
Messages: 1389
Registered: July 2009
Senior Member
Hello,

The bug you filed is light on details - it should have all the settings used and all the steps required to reproduce the problem, but a test case is prefered.

You mention you use the static weaving property. This error could be caused if you use the static weaving property but have not run the static weaver on your classes. Could it be that it was not run on your latest entity jar but was run in the past? If static weaving was run, please also upload the weaved classes to the bug, and the steps used in running the weaver.

Best Regards,
Chris
Re: NPE when using LAZY loading on ManyToOne relationship [message #649775 is a reply to message #649742] Thu, 20 January 2011 15:01 Go to previous messageGo to next message
Daniel Le Berre is currently offline Daniel Le BerreFriend
Messages: 82
Registered: July 2009
Member
I have a test case to reproduce that problem, embedded in my current project.

I can create a simple eclipse project that shows the problem.

I will attach it to my bug report.

Update: just done it.

[Updated on: Thu, 20 January 2011 17:02]

Report message to a moderator

Re: NPE when using LAZY loading on ManyToOne relationship [message #649832 is a reply to message #649742] Thu, 20 January 2011 17:09 Go to previous messageGo to next message
Daniel Le Berre is currently offline Daniel Le BerreFriend
Messages: 82
Registered: July 2009
Member
Regarding the static weaving, I do not do anything by hand.

It is done automatically by EclipseLink on deployment, thanks to the eclipselink.weaving=static property.

I see this in the logs:
[EL Finer]: 2011-01-20 17:57:55.323--ServerSession(959993440)--Thread(Thread[main,5 ,main])--Class [bug.eclipselink.A] registered to be processed by weaver.
[EL Finer]: 2011-01-20 17:57:55.325--ServerSession(959993440)--Thread(Thread[main,5 ,main])--Class [bug.eclipselink.B] registered to be processed by weaver.

which tend to confirm that weaving is about to take place.

I do not know if the weaver is supposed to log a message too.

It might be the case that the weaving is not taking place soon enough in that case.

Re: NPE when using LAZY loading on ManyToOne relationship [message #649898 is a reply to message #649832] Thu, 20 January 2011 21:48 Go to previous messageGo to next message
Chris Delahunt is currently offline Chris DelahuntFriend
Messages: 1389
Registered: July 2009
Senior Member
Hello Daniel,

The problem is that by using the property name="eclipselink.weaving" value="static" in your persistence.xml, you are stating that entities have already been weaved. This means that EclipseLink will not attempt to weave the classes again. Since they have not been weaved, an exception occurs when it attempts to check the B->A relationship. It looks for the ._persistence_get_a_vh method because this relationship is marked with FetchType.LAZY and it thinks it has been woven, which it hasn't.

Please see the link I posted previously for information on how the different weaving options work, and more specifically http://wiki.eclipse.org/Using_EclipseLink_JPA_Extensions_(ELUG)#How_to_Configure_Static_Weaving_for_JPA_Entities
for static weaving. Options are either statically weave your compiled classes before deployment or remove the eclipselink.weaving" value="static" property and use dynamic weaving, or not use fetch.Lazy on the B->A relationship.

Best Regards,
Chris
Re: NPE when using LAZY loading on ManyToOne relationship [message #649904 is a reply to message #649898] Thu, 20 January 2011 22:01 Go to previous messageGo to next message
Daniel Le Berre is currently offline Daniel Le BerreFriend
Messages: 82
Registered: July 2009
Member
hum, did that behavior changed recently?

I have been using EclipseLink since 1.0 that way. One of the reason I switched from OpenJPA to EclipseLink was that I did not have to perform the weaving myself.

I have apps running with that configuration Shocked
Re: NPE when using LAZY loading on ManyToOne relationship [message #649910 is a reply to message #649904] Thu, 20 January 2011 22:39 Go to previous message
Daniel Le Berre is currently offline Daniel Le BerreFriend
Messages: 82
Registered: July 2009
Member
ok, I confirm that adding dynamic weaving solves the problem (using -javaagent:/path/to/eclipselink.jar: the wiki suggests that providing the jar filename is fine as long as it is on the classpath, but I do not think it is correct).

Since that weaving is only used for some specific tasks in EclipseLink, i have been able to live without it up to now.

Since I am a maven user, I spotted that way to perform static weaving with maven:
http://www.tzavellas.com/techblog/2008/10/17/statically-weav ing-jpa-entities-for-eclipselink-using-maven/

Thank you so much for your help Chris!
Previous Topic:optional vs nullable attributes
Next Topic:Querying ManyToMany relationship
Goto Forum:
  


Current Time: Fri Mar 29 01:44:18 GMT 2024

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

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

Back to the top