2014-10-30 95 views
1

我有以下代碼。在Websphere上訪問EntityManager時出現NullPointerException

public class PersistableProcessStepStatus extends ProcessStepStatus { 
    @PersistenceContext(unitName = "primary") 
    private EntityManager entityManager;  
    private void changeFlag(String namedQuery, String flag, boolean enable) { 
       getEntityManager().createNamedQuery(namedQuery) 
           .setParameter("a", prozessName) 
           .setParameter("b", vorgangName) 
           .setParameter(flag, enable).executeUpdate(); 
     } 
    [...] 
} 

我通過JMX控制檯調用我的方法,並且它轉到更改Flag方法,其中拋出異常。實體經理在我的應用程序的其他部分工作。此應用程序運行在Websphere 8.5.5.1

我還沒有找到JPATxEntityManager的源代碼,所以我真的不知道如何處理。

這是通過調用createNamedQuery方法拋出的異常。

[30/10/14 15:18:34:805 CET] 000002a7 SystemErr  R java.lang.NullPointerException 
[30/10/14 15:18:34:805 CET] 000002a7 SystemErr  R at com.ibm.ws.jpa.management.JPATxEntityManager.getEMInvocationInfo(JPATxEntityManager.java:218) 
[30/10/14 15:18:34:805 CET] 000002a7 SystemErr  R at com.ibm.ws.jpa.management.JPATxEntityManager.getEMInvocationInfo(JPATxEntityManager.java:191) 
[30/10/14 15:18:34:806 CET] 000002a7 SystemErr  R at com.ibm.ws.jpa.management.JPAEntityManager.createNamedQuery(JPAEntityManager.java:312) 
[30/10/14 15:18:38:694 CET] 000002a7 SystemErr  R at public.PersistableProcessStepStatus.changeFlag(PersistableProcessStepStatus.java:34) 
[30/10/14 15:18:38:694 CET] 000002a7 SystemErr  R at public.PersistableProcessStepStatus.enableDebugMode(PersistableProcessStepStatus.java:51) 
[30/10/14 15:18:38:694 CET] 000002a7 SystemErr  R at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
[30/10/14 15:18:38:694 CET] 000002a7 SystemErr  R at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:60) 
[30/10/14 15:18:38:694 CET] 000002a7 SystemErr  R at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37) 
[30/10/14 15:18:38:694 CET] 000002a7 SystemErr  R at java.lang.reflect.Method.invoke(Method.java:611) 
[30/10/14 15:18:38:694 CET] 000002a7 SystemErr  R at sun.reflect.misc.Trampoline.invoke(MethodUtil.java:69) 
[30/10/14 15:18:38:694 CET] 000002a7 SystemErr  R at sun.reflect.GeneratedMethodAccessor33.invoke(Unknown Source) 
[30/10/14 15:18:38:695 CET] 000002a7 SystemErr  R at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37) 
[30/10/14 15:18:38:695 CET] 000002a7 SystemErr  R at java.lang.reflect.Method.invoke(Method.java:611) 
[30/10/14 15:18:38:695 CET] 000002a7 SystemErr  R at sun.reflect.misc.MethodUtil.invoke(MethodUtil.java:272) 
[30/10/14 15:18:38:695 CET] 000002a7 SystemErr  R at javax.management.modelmbean.RequiredModelMBean$4.run(RequiredModelMBean.java:1152) 
[30/10/14 15:18:38:695 CET] 000002a7 SystemErr  R at java.security.AccessController.doPrivileged(AccessController.java:298) 
[30/10/14 15:18:38:695 CET] 000002a7 SystemErr  R at com.ibm.oti.security.CheckedAccessControlContext.securityCheck(CheckedAccessControlContext.java:30) 
[30/10/14 15:18:38:695 CET] 000002a7 SystemErr  R at sun.misc.JavaSecurityAccessWrapper.doIntersectionPrivilege(JavaSecurityAccessWrapper.java:41) 
[30/10/14 15:18:38:695 CET] 000002a7 SystemErr  R at javax.management.modelmbean.RequiredModelMBean.invokeMethod(RequiredModelMBean.java:1146) 
[30/10/14 15:18:38:695 CET] 000002a7 SystemErr  R at javax.management.modelmbean.RequiredModelMBean.invoke(RequiredModelMBean.java:999) 
[30/10/14 15:18:38:696 CET] 000002a7 SystemErr  R at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:847) 
[30/10/14 15:18:38:696 CET] 000002a7 SystemErr  R at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:783) 
[30/10/14 15:18:38:696 CET] 000002a7 SystemErr  R at com.ibm.ws.management.AdminServiceImpl$1.run(AdminServiceImpl.java:1335) 
[30/10/14 15:18:38:696 CET] 000002a7 SystemErr  R at com.ibm.ws.security.util.AccessController.doPrivileged(AccessController.java:118) 
[30/10/14 15:18:38:696 CET] 000002a7 SystemErr  R at com.ibm.ws.management.AdminServiceImpl.invoke(AdminServiceImpl.java:1228) 
[30/10/14 15:18:38:696 CET] 000002a7 SystemErr  R at com.ibm.ws.management.remote.AdminServiceForwarder.invoke(AdminServiceForwarder.java:346) 
[30/10/14 15:18:38:696 CET] 000002a7 SystemErr  R at javax.management.remote.rmi.RMIConnectionImpl.doOperation(RMIConnectionImpl.java:1466) 
[30/10/14 15:18:38:696 CET] 000002a7 SystemErr  R at javax.management.remote.rmi.RMIConnectionImpl.access$300(RMIConnectionImpl.java:86) 
[30/10/14 15:18:38:696 CET] 000002a7 SystemErr  R at javax.management.remote.rmi.RMIConnectionImpl$PrivilegedOperation.run(RMIConnectionImpl.java:1307) 
[30/10/14 15:18:38:696 CET] 000002a7 SystemErr  R at javax.management.remote.rmi.RMIConnectionImpl.doPrivilegedOperation(RMIConnectionImpl.java:1399) 
[30/10/14 15:18:38:696 CET] 000002a7 SystemErr  R at javax.management.remote.rmi.RMIConnectionImpl.invoke(RMIConnectionImpl.java:830) 
[30/10/14 15:18:38:697 CET] 000002a7 SystemErr  R at javax.management.remote.rmi._RMIConnectionImpl_Tie.invoke(_RMIConnectionImpl_Tie.java:751) 
[30/10/14 15:18:38:697 CET] 000002a7 SystemErr  R at javax.management.remote.rmi._RMIConnectionImpl_Tie._invoke(_RMIConnectionImpl_Tie.java:158) 
[30/10/14 15:18:38:697 CET] 000002a7 SystemErr  R at com.ibm.CORBA.iiop.ServerDelegate.dispatchInvokeHandler(ServerDelegate.java:631) 
[30/10/14 15:18:38:697 CET] 000002a7 SystemErr  R at com.ibm.CORBA.iiop.ServerDelegate.dispatch(ServerDelegate.java:501) 
[30/10/14 15:18:38:697 CET] 000002a7 SystemErr  R at com.ibm.rmi.iiop.ORB.process(ORB.java:622) 
[30/10/14 15:18:38:697 CET] 000002a7 SystemErr  R at com.ibm.CORBA.iiop.ORB.process(ORB.java:1581) 
[30/10/14 15:18:38:697 CET] 000002a7 SystemErr  R at com.ibm.rmi.iiop.Connection.doRequestWork(Connection.java:3148) 
[30/10/14 15:18:38:697 CET] 000002a7 SystemErr  R at com.ibm.rmi.iiop.Connection.doWork(Connection.java:3013) 
[30/10/14 15:18:38:697 CET] 000002a7 SystemErr  R at com.ibm.rmi.iiop.WorkUnitImpl.doWork(WorkUnitImpl.java:63) 
[30/10/14 15:18:38:697 CET] 000002a7 SystemErr  R at com.ibm.ejs.oa.pool.PooledThread.run(ThreadPool.java:118) 
[30/10/14 15:18:38:698 CET] 000002a7 SystemErr  R at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1864) 
+1

這是一個MBean?這是一個猜測,但我會說它不與JTA交易相關聯。嘗試將註釋更改爲@PersistenceUnit並手動啓動事務。 – Gas 2014-10-30 19:15:10

回答

0

因此,解決的辦法是:

在persistence.xml中創建persistente-utnit

<persistence-unit name="second" transaction-type="RESOURCE_LOCAL"> 

和變化類:

@TransactionManagement(TransactionManagementType.BEAN) 
public class PersistableProcessStepStatus extends ProcessStepStatus { 
@PersistenceUnit(unitName = "second") 
private EntityManagerFactory entityManagerFactory; 

private void changeFlag(String namedQuery, String flag, boolean enable) { 
    entityManager = entityManagerFactory.createEntityManager(); 

    entityManager.getTransaction().begin(); 
    entityManager.createNamedQuery(namedQuery) 
      .setParameter("a", prozessName) 
      .setParameter("b", vorgangName) 
      .setParameter(flag, enable).executeUpdate(); 
    entityManager.getTransaction().commit(); 

}

相關問題