Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Persistence with JPA - Container-Managed throws exception

I am following tutorial/sample: Adding Container-Managed Persistence with JPA (Java EE 6 Web Profile SDK) - trial account

Adding Container-Managed Persistence with JPA

I get this message in browsers web page:

Persistence with JPA! Persistence operation failed with reason: The bean encountered a non-application exception; nested exception is: java.lang.NullPointerException

I follow the process several times but always same error.

In console when I tried to run locally I get this:

java version "1.7.0_79"

Java(TM) SE Runtime Environment (build 1.7.0_79-b15)

Java HotSpot(TM) 64-Bit Server VM (build 24.79-b02, mixed mode)

C:\Users\Matej\temp-Workspace\Servers\Java EE 6 Web Profile Server-config>"C:\Program Files\Java\jre7\bin\java" -server -javaagent:"C:\Users\Matej\TEMP-W~1\Servers\JAVAEE~1\lib\openejb-javaagent_4.5.2.jar"  -XX:ErrorFile="C:\Users\Matej\TEMP-W~1\Servers\JAVAEE~1\log\error.log" -XX:HeapDumpPath="C:\Users\Matej\TEMP-W~1\Servers\JAVAEE~1\log\heap_dump.hprof" "-XX:+HeapDumpOnOutOfMemoryError" "-XX:+DisableExplicitGC" "-Xms512m" "-Xmx1024m" "-XX:PermSize=256M" "-XX:MaxPermSize=256M" "-Dcom.sun.management.jmxremote.port=1717" "-Dcom.sun.management.jmxremote.authenticate=false" "-Dcom.sun.management.jmxremote.ssl=false" "-Dosgi.requiredJavaVersion=1.6" "-DuseNaming=osgi" "-Dosgi.install.area=." "-Djava.io.tmpdir=./work/tmp" "-Djava.endorsed.dirs=lib/endorsed" "-Dorg.eclipse.equinox.simpleconfigurator.exclusiveInstallation=false" "-Dcom.sap.core.process=ljs_node" "-Declipse.ignoreApp=true" "-Dosgi.noShutdown=true" "-Dosgi.framework.activeThreadType=normal" "-Dosgi.embedded.cleanupOnSave=true" "-Dosgi.usesLimit=30" "-Djava.awt.headless=true" "-Djava.rmi.server.hostname=127.0.0.1" -classpath "C:\Users\Matej\TEMP-W~1\Servers\JAVAEE~1\lib\openejb-javaagent_4.5.2.jar;C:\Users\Matej\TEMP-W~1\Servers\JAVAEE~1\lib\org.eclipse.virgo.nano.authentication_3.6.2.RELEASE.jar;C:\Users\Matej\TEMP-W~1\Servers\JAVAEE~1\lib\org.eclipse.virgo.nano.shutdown_3.6.2.RELEASE.jar;C:\Users\Matej\TEMP-W~1\Servers\JAVAEE~1\lib\org.eclipse.virgo.util.env_3.6.2.RELEASE.jar;C:\Users\Matej\TEMP-W~1\Servers\JAVAEE~1\plugins\org.eclipse.equinox.launcher_1.3.0.v20120308-1358.jar"  org.eclipse.equinox.launcher.Main  -console -dev "file:C:/Users/Matej/temp-Workspace/Servers/Java EE 6 Web Profile Server-config/configuration/dev.properties"

osgi>

This is log from server:

FILE_TYPE:DAAA96DE-B0FB-4c6e-AF7B-A445F5BF9BE2

FILE_ID:1446460764869

ENCODING:[UTF8|NWCJS:ASCII]

RECORD_SEPARATOR:124

COLUMN_SEPARATOR:35

ESC_CHARACTER:92

COLUMNS:Time|TZone|Severity|Logger|ACH|User|Thread|Bundle name|JPSpace|JPAppliance|JPComponent|Tenant Alias|Text|

SEVERITY_MAP:FINEST|Information|FINER|Information|FINE|Information|CONFIG|Information|DEBUG|Information|PATH|Information|INFO|Information|WARNING|Warning|ERROR|Error|SEVERE|Error|FATAL|Error

HEADER_END

2015 11 02 10:40:10#+00#ERROR#com.sap.cloud.sample.persistence.PersistenceEJBServlet##anonymous#http-bio-8041-exec-1#na#s0015145715trial#persistance#web#s0015145715trial#Persistence operation failedjavax.ejb.EJBException: The bean encountered a non-application exception; nested exception is:

  java.lang.NullPointerException: while trying to invoke the method javax.persistence.EntityManager.createNamedQuery(java.lang.String) of a null object loaded from field com.sap.cloud.sample.persistence.PersonBean.em of an object loaded from local variable 'this'

  at org.apache.openejb.core.ivm.BaseEjbProxyHandler.convertException(BaseEjbProxyHandler.java:363)

  at org.apache.openejb.core.ivm.BaseEjbProxyHandler.invoke(BaseEjbProxyHandler.java:283)

  at com.sap.cloud.sample.persistence.PersonBean$LocalBeanProxy.getAllPersons(com/sap/cloud/sample/persistence/PersonBean.java)

  at com.sap.cloud.sample.persistence.PersistenceEJBServlet.appendPersonTable(PersistenceEJBServlet.java:67)

  at com.sap.cloud.sample.persistence.PersistenceEJBServlet.doGet(PersistenceEJBServlet.java:39)

  at javax.servlet.http.HttpServlet.service(HttpServlet.java:735)

  at javax.servlet.http.HttpServlet.service(HttpServlet.java:848)

  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)

  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)

  at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)

  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)

  at com.sap.core.communication.server.CertValidatorFilter.doFilter(CertValidatorFilter.java:321)

  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)

  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)

  at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)

  at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)

  at org.eclipse.virgo.web.enterprise.security.valve.OpenEjbSecurityInitializationValve.invoke(OpenEjbSecurityInitializationValve.java:44)

  at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)

  at com.sap.core.jpaas.security.auth.service.lib.AbstractAuthenticator.invoke(AbstractAuthenticator.java:205)

  at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)

  at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956)

  at com.sap.core.tenant.valve.TenantValidationValve.invokeNextValve(TenantValidationValve.java:215)

  at com.sap.core.tenant.valve.TenantValidationValve.invoke(TenantValidationValve.java:94)

  at com.sap.js.statistics.tomcat.valve.RequestTracingValve.invoke(RequestTracingValve.java:24)

  at com.sap.core.js.monitoring.tomcat.valve.RequestTracingValve.invoke(RequestTracingValve.java:25)

  at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)

  at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)

  at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:423)

  at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1079)

  at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:625)

  at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)

  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)

  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)

  at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)

  at java.lang.Thread.run(Thread.java:812)

Caused by: java.lang.NullPointerException: while trying to invoke the method javax.persistence.EntityManager.createNamedQuery(java.lang.String) of a null object loaded from field com.sap.cloud.sample.persistence.PersonBean.em of an object loaded from local variable 'this'

  at com.sap.cloud.sample.persistence.PersonBean.getAllPersons(PersonBean.java:21)

  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)

  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

  at java.lang.reflect.Method.invoke(Method.java:606)

  at org.apache.openejb.core.interceptor.ReflectionInvocationContext$Invocation.invoke(ReflectionInvocationContext.java:181)

  at org.apache.openejb.core.interceptor.ReflectionInvocationContext.proceed(ReflectionInvocationContext.java:163)

  at org.apache.openejb.cdi.CdiInterceptor.invoke(CdiInterceptor.java:126)

  at org.apache.openejb.cdi.CdiInterceptor.access$000(CdiInterceptor.java:42)

  at org.apache.openejb.cdi.CdiInterceptor$1.call(CdiInterceptor.java:63)

  at org.apache.openejb.cdi.CdiInterceptor.aroundInvoke(CdiInterceptor.java:69)

  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)

  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

  at java.lang.reflect.Method.invoke(Method.java:606)

  at org.apache.openejb.core.interceptor.ReflectionInvocationContext$Invocation.invoke(ReflectionInvocationContext.java:181)

  at org.apache.openejb.core.interceptor.ReflectionInvocationContext.proceed(ReflectionInvocationContext.java:163)

  at org.apache.openejb.monitoring.StatsInterceptor.record(StatsInterceptor.java:176)

  at org.apache.openejb.monitoring.StatsInterceptor.invoke(StatsInterceptor.java:95)

  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)

  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

  at java.lang.reflect.Method.invoke(Method.java:606)

  at org.apache.openejb.core.interceptor.ReflectionInvocationContext$Invocation.invoke(ReflectionInvocationContext.java:181)

  at org.apache.openejb.core.interceptor.ReflectionInvocationContext.proceed(ReflectionInvocationContext.java:163)

  at org.apache.openejb.core.interceptor.InterceptorStack.invoke(InterceptorStack.java:138)

  at org.apache.openejb.core.stateless.StatelessContainer._invoke(StatelessContainer.java:239)

  at org.apache.openejb.core.stateless.StatelessContainer.invoke(StatelessContainer.java:191)

  at org.apache.openejb.core.ivm.EjbObjectProxyHandler.synchronizedBusinessMethod(EjbObjectProxyHandler.java:246)

  at org.apache.openejb.core.ivm.EjbObjectProxyHandler.businessMethod(EjbObjectProxyHandler.java:241)

  at org.apache.openejb.core.ivm.EjbObjectProxyHandler._invoke(EjbObjectProxyHandler.java:83)

  at org.apache.openejb.core.ivm.BaseEjbProxyHandler.invoke(BaseEjbProxyHandler.java:279)

  ... 34 common frames omitted

|

Tags:
Former Member
Former Member replied

You need to update your persistence.xml file to:

<?xml version="1.0" encoding="UTF-8"?>

<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">

    <persistence-unit name="persistence-with-ejb" transaction-type="JTA">

        <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>

        <jta-data-source>jdbc/DefaultDB</jta-data-source>

        <class>com.sap.cloud.sample.persistence.Person</class>

        <properties>

            <property name="eclipselink.ddl-generation" value="create-tables" />

            <property name="eclipselink.logging.level" value="SEVERE" />

        </properties>

    </persistence-unit>

</persistence>

I send this to info dev colleagues - they will add this to the page.

BR,

Dobri

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question