Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] Eclipselink 2.0 + Entity Listeners + Container Managed Transactions

This is a preUpdate event, it occurs before the update to the database, not
during the merge().  The update to the database does not occur until commit. 
I'm not sure why your context is null, it is still in the JTA transaction,
just the beforeCompletion event of the transaction.

If you call flush() in your code after the merge(), then the database will
be updated during the call.

What are you trying to do in your event?


jzqa wrote:
> 
> Hi All,
> 
> Environment: Weblogic 10.3.0, Eclipselink 2.0, JPA 2.0, EJB 3.0, Container
> Managed JTA Transactions & EntityManager
> Problem:
> I am facing a difficulty in following situation. My entities have entity
> listeners (preupdate, prepersist etc), which get current EJBContext and
> call
> methods e.g. isCallerInRole() and getCallerPrincipal() etc. All
> entitymanager methods e.g. persist(), remove() and query() are working as
> expected. But problem comes in merge(), when transaction commits and
> entitymanager is synchronized to DB. In one of the entity listeners i get
> below mentioned error while trying to access EJBContext. Somehow at that
> point in EJBContext becomes invalid. Question is why? My understanding is
> that entity listeners are all called within JTA transaction, and at the
> time
> when listeners are executing EJBContext should be valid as it happens in
> persist(), remove() etc operations.
> 
> 
> To drill down further i put a print statement in finally block of ejb
> method. This print statement should be executed after all entity listeners
> are executed. But its not the case.
> 
> My EJB method is simple:
> 
> 
> @Override
> public void update(BaseModel obj) {
>  try {
> new BaseDAOImpl().update(obj);
>  } finally {
>  System.out.println("update"); // JPA entity listeners are executed after
> this finally block, why?
>  }
> }
> 
> I get following error:
> 
> Caused by: java.lang.NullPointerException
>         at
> weblogic.ejb.container.internal.EJBContextManager.getEJBContext(EJBContextManager.java:51)
>         at
> weblogic.ejb.container.deployer.SessionContextProxyImpl.getDelegate(SessionContextProxyImpl.java:31)
>         at
> weblogic.ejb.container.deployer.SessionContextProxyImpl.isCallerInRole(SessionContextProxyImpl.java:81)
>         at
> com.warid.campaign.service.util.WeblogicContextImpl.isCallerInRole(WeblogicContextImpl.java:69)
>         at
> com.warid.campaign.model.listeners.UserOwnershipValidationListener.validateUserOwnership(UserOwnershipValidationListener.java:16)
>         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.eclipse.persistence.internal.security.PrivilegedAccessHelper.invokeMethod(PrivilegedAccessHelper.java:346)
>         at
> org.eclipse.persistence.internal.jpa.metadata.listeners.EntityListener.invokeMethod(EntityListener.java:297)
>         at
> org.eclipse.persistence.internal.jpa.metadata.listeners.EntityListener.invokeMethod(EntityListener.java:318)
>         at
> org.eclipse.persistence.internal.jpa.metadata.listeners.EntityListener.preUpdateWithChanges(EntityListener.java:413)
>         at
> org.eclipse.persistence.descriptors.DescriptorEventManager.notifyListener(DescriptorEventManager.java:676)
>         at
> org.eclipse.persistence.descriptors.DescriptorEventManager.notifyEJB30Listeners(DescriptorEventManager.java:596)
>         at
> org.eclipse.persistence.descriptors.DescriptorEventManager.executeEvent(DescriptorEventManager.java:200)
>         at
> org.eclipse.persistence.internal.queries.DatabaseQueryMechanism.updateObjectForWriteWithChangeSet(DatabaseQueryMechanism.java:1078)
>         at
> org.eclipse.persistence.queries.UpdateObjectQuery.executeCommitWithChangeSet(UpdateObjectQuery.java:84)
>         at
> org.eclipse.persistence.internal.queries.DatabaseQueryMechanism.executeWriteWithChangeSet(DatabaseQueryMechanism.java:286)
>         at
> org.eclipse.persistence.queries.WriteObjectQuery.executeDatabaseQuery(WriteObjectQuery.java:58)
>         at
> org.eclipse.persistence.queries.DatabaseQuery.execute(DatabaseQuery.java:675)
>         at
> org.eclipse.persistence.queries.DatabaseQuery.executeInUnitOfWork(DatabaseQuery.java:589)
>         at
> org.eclipse.persistence.queries.ObjectLevelModifyQuery.executeInUnitOfWorkObjectLevelModifyQuery(ObjectLevelModifyQuery.java:109)
>         at
> org.eclipse.persistence.queries.ObjectLevelModifyQuery.executeInUnitOfWork(ObjectLevelModifyQuery.java:86)
>         at
> org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.internalExecuteQuery(UnitOfWorkImpl.java:2857)
>         at
> org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1225)
>         at
> org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1207)
>         at
> org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1167)
>         at
> org.eclipse.persistence.internal.sessions.CommitManager.commitChangedObjectsForClassWithChangeSet(CommitManager.java:233)
>         at
> org.eclipse.persistence.internal.sessions.CommitManager.commitAllObjectsWithChangeSet(CommitManager.java:108)
>         at
> org.eclipse.persistence.internal.sessions.AbstractSession.writeAllObjectsWithChangeSet(AbstractSession.java:3260)
>         at
> org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.commitToDatabase(UnitOfWorkImpl.java:1403)
>         at
> org.eclipse.persistence.internal.sessions.RepeatableWriteUnitOfWork.commitToDatabase(RepeatableWriteUnitOfWork.java:547)
>         at
> org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.commitToDatabaseWithChangeSet(UnitOfWorkImpl.java:1508)
>         at
> org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.issueSQLbeforeCompletion(UnitOfWorkImpl.java:3128)
>         at
> org.eclipse.persistence.internal.sessions.RepeatableWriteUnitOfWork.issueSQLbeforeCompletion(RepeatableWriteUnitOfWork.java:268)
>         at
> org.eclipse.persistence.transaction.AbstractSynchronizationListener.beforeCompletion(AbstractSynchronizationListener.java:157)
>         at
> org.eclipse.persistence.transaction.JTASynchronizationListener.beforeCompletion(JTASynchronizationListener.java:68)
>         at
> weblogic.transaction.internal.ServerSCInfo.doBeforeCompletion(ServerSCInfo.java:1217)
>         at
> weblogic.transaction.internal.ServerSCInfo.callBeforeCompletions(ServerSCInfo.java:1195)
>         at
> weblogic.transaction.internal.ServerSCInfo.startPrePrepareAndChain(ServerSCInfo.java:118)
>         at
> weblogic.transaction.internal.ServerTransactionImpl.localPrePrepareAndChain(ServerTransactionImpl.java:1302)
>         at
> weblogic.transaction.internal.ServerTransactionImpl.globalPrePrepare(ServerTransactionImpl.java:2114)
>         at
> weblogic.transaction.internal.ServerTransactionImpl.internalCommit(ServerTransactionImpl.java:263)
>         at
> weblogic.transaction.internal.ServerTransactionImpl.commit(ServerTransactionImpl.java:230)
>         at
> weblogic.ejb.container.internal.BaseLocalObject.postInvoke1(BaseLocalObject.java:591)
>         ... 64 more
> 
> Thanks
> 
> Regards,
> Jehanzeb Qayyum
> 
> 
> 


-----
http://wiki.eclipse.org/User:James.sutherland.oracle.com James Sutherland 
http://www.eclipse.org/eclipselink/
 EclipseLink ,  http://www.oracle.com/technology/products/ias/toplink/
TopLink 
Wiki:  http://wiki.eclipse.org/EclipseLink EclipseLink , 
http://wiki.oracle.com/page/TopLink TopLink 
Forums:  http://forums.oracle.com/forums/forum.jspa?forumID=48 TopLink , 
http://www.nabble.com/EclipseLink-f26430.html EclipseLink 
Book:  http://en.wikibooks.org/wiki/Java_Persistence Java Persistence 
-- 
View this message in context: http://old.nabble.com/Eclipselink-2.0-%2B-Entity-Listeners-%2B-Container-Managed-Transactions-tp28078583p28084210.html
Sent from the EclipseLink - Users mailing list archive at Nabble.com.



Back to the top