NPE in MethodAttributeAccessor.getAttributeValueFromObject() [message #915881] |
Tue, 18 September 2012 02:36  |
Eclipse User |
|
|
|
Hi all,
Before I go through the trouble of creating a simple reproducable test
case I would first like to check if what I am doing is out of the
ordinary and possibly not even supported by EclipseLink (or JPA).
I have two persistence units A and B. The persistence unit A contains an
entity A:
@Entity
public class A {
@Id private Long id;
}
And the persistence unit B contains an entity B:
@Entity
public class B {
@ElementCollection
@CollectionTable("B_AS")
private Collection<AId> as;
}
and with AId as:
@Embeddable
public class AId {
private Long id;
public Long getId() { return id; }
}
As you can see B thus indirectly references A.
The problem I now have is that when I write JPQL queries against B I
sometimes get NPEs thrown from EclipseLink (2.3.2):
javax.persistence.PersistenceException: Exception [EclipseLink-70]
(Eclipse Persistence Services - 2.3.2.v20111125-r10461):
org.eclipse.persistence.exceptions.DescriptorException
Exception Description: A NullPointerException was thrown while
extracting a value through the method [getId] in the object [pua.AId].
Internal Exception: java.lang.NullPointerException
Mapping: org.eclipse.persistence.mappings.DirectToFieldMapping[id-->ID]
Descriptor: RelationalDescriptor(pua.AId --> [DatabaseTable(PUB.B_AS)])
at
org.eclipse.persistence.internal.jpa.EntityManagerImpl.flush(EntityManagerImpl.java:786)
at
org.eclipse.persistence.internal.jpa.EJBQueryImpl.performPreQueryFlush(EJBQueryImpl.java:1298)
at
org.eclipse.persistence.internal.jpa.EJBQueryImpl.executeReadQuery(EJBQueryImpl.java:434)
at
org.eclipse.persistence.internal.jpa.EJBQueryImpl.getResultList(EJBQueryImpl.java:742)
at
com.avaloq.tools.repository.internal.server.ResourceEntityManager.namedQueryResults(ResourceEntityManager.java:338)
at
com.avaloq.tools.repository.internal.delivery.server.CategoryServiceDelegate.getByCustomerIssue(CategoryServiceDelegate.java:168)
at
com.avaloq.tools.repository.internal.delivery.server.CategoryService.getByCustomerIssue(CategoryService.java:82)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at
org.glassfish.ejb.security.application.EJBSecurityManager.runMethod(EJBSecurityManager.java:1052)
at
org.glassfish.ejb.security.application.EJBSecurityManager.invoke(EJBSecurityManager.java:1124)
at
com.sun.ejb.containers.BaseContainer.invokeBeanMethod(BaseContainer.java:5388)
at com.sun.ejb.EjbInvocation.invokeBeanMethod(EjbInvocation.java:619)
at
com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:800)
at com.sun.ejb.EjbInvocation.proceed(EjbInvocation.java:571)
at
com.sun.ejb.containers.interceptors.SystemInterceptorProxy.doAround(SystemInterceptorProxy.java:162)
at
com.sun.ejb.containers.interceptors.SystemInterceptorProxy.aroundInvoke(SystemInterceptorProxy.java:144)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at
com.sun.ejb.containers.interceptors.AroundInvokeInterceptor.intercept(InterceptorManager.java:861)
at
com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:800)
at
com.sun.ejb.containers.interceptors.InterceptorManager.intercept(InterceptorManager.java:370)
at com.sun.ejb.containers.BaseContainer.__intercept(BaseContainer.java:5360)
at com.sun.ejb.containers.BaseContainer.intercept(BaseContainer.java:5348)
at
com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:214)
.... 44 more
Caused by: Exception [EclipseLink-70] (Eclipse Persistence Services -
2.3.2.v20111125-r10461):
org.eclipse.persistence.exceptions.DescriptorException
Exception Description: A NullPointerException was thrown while
extracting a value through the method [getId] in the object [pua.AId].
Internal Exception: java.lang.NullPointerException
Mapping: org.eclipse.persistence.mappings.DirectToFieldMapping[id-->ID]
Descriptor:
RelationalDescriptor(com.avaloq.tools.model.issue.common.IssuePrimaryKey
--> [DatabaseTable(PUB.B_AS)])
at
org.eclipse.persistence.exceptions.DescriptorException.nullPointerWhileGettingValueThruMethodAccessor(DescriptorException.java:1272)
at
org.eclipse.persistence.internal.descriptors.MethodAttributeAccessor.getAttributeValueFromObject(MethodAttributeAccessor.java:92)
at
org.eclipse.persistence.internal.descriptors.MethodAttributeAccessor.getAttributeValueFromObject(MethodAttributeAccessor.java:61)
at
org.eclipse.persistence.mappings.DatabaseMapping.getAttributeValueFromObject(DatabaseMapping.java:516)
at
org.eclipse.persistence.mappings.foundation.AbstractDirectMapping.compareObjects(AbstractDirectMapping.java:440)
at
org.eclipse.persistence.mappings.foundation.AbstractDirectMapping.compareForChange(AbstractDirectMapping.java:392)
at
org.eclipse.persistence.descriptors.changetracking.DeferredChangeDetectionPolicy.createObjectChangeSetThroughComparison(DeferredChangeDetectionPolicy.java:177)
at
org.eclipse.persistence.descriptors.changetracking.DeferredChangeDetectionPolicy.createObjectChangeSet(DeferredChangeDetectionPolicy.java:137)
at
org.eclipse.persistence.descriptors.changetracking.DeferredChangeDetectionPolicy.calculateChanges(DeferredChangeDetectionPolicy.java:89)
at
org.eclipse.persistence.descriptors.changetracking.DeferredChangeDetectionPolicy.calculateChangesForExistingObject(DeferredChangeDetectionPolicy.java:54)
at
org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.calculateChanges(UnitOfWorkImpl.java:643)
at
org.eclipse.persistence.internal.sessions.RepeatableWriteUnitOfWork.writeChanges(RepeatableWriteUnitOfWork.java:433)
at
org.eclipse.persistence.internal.jpa.EntityManagerImpl.flush(EntityManagerImpl.java:780)
.... 72 more
Caused by: java.lang.NullPointerException
at
org.eclipse.persistence.internal.descriptors.MethodAttributeAccessor.getAttributeValueFromObject(MethodAttributeAccessor.java:82)
.... 83 more
Does the setup as explained look correct to you? Should I try to create
a reproducable test case for this?
Regards,
--knut
|
|
|
|
|
|
|
|
|
|
|
|
Re: NPE in MethodAttributeAccessor.getAttributeValueFromObject() [message #919997 is a reply to message #918928] |
Sat, 22 September 2012 12:01  |
Eclipse User |
|
|
|
Hi Chris,
It seems like I will have to try to narrow this down. Yes, you are
right, the problem is occurring as part of a transaction commit. The
transaction commit is occurring since the report query is being executed
within a container-managed JTA transaction. But the only thing the
transaction does is to execute a JPQL report query as simple as:
select b.as
from b b
where b.id = :id
It seems like the query execution registers objects in the unit of work
which on commit are checked for possible changes. So I suppose a
workaround may be to call EntityManager#clear() before the transaction ends.
Regards,
--knut
On 9/21/12 15:45, Chris Delahunt wrote:
> The stack trace shows that this is occuring on a transaction commit, not
> on a query as you stated. It seems to be the same problem you originally
> posted - once your context has the problem with the embeddable, the NPE
> will occur on any flush or transaction commit.
> Since you are reusing the AId in both a collection and as A's pk class,
> are you reusing the same object in both as well? They should not be
> shared - B should have its own AId instance in its collection that is a
> different from the instance in A, even though the values held might be
> the same. Embeddable instances should not be shared, and might result in
> this exception.
>
> Best Regards,
> Chris
|
|
|
Powered by
FUDForum. Page generated in 0.51980 seconds