7

I get a NullPointerException on the console of my tomcat at my first connection to the database with createEntityManager(). I am using:

  • apache tomcat 8.0.24
  • eclipselink 2.6.1-RC1 (indirectly used by JPA)
  • sqlite jdbc 3.8.10.1

The log message is the following:

[EL Warning]: connection: 2015-08-21 16:01:51.569--java.lang.NullPointerException
[EL Info]: 2015-08-21 16:01:51.585--ServerSession(29156874)--EclipseLink, version: Eclipse Persistence Services - 2.6.1.v20150605-31e8258
[EL Info]: connection: 2015-08-21 16:01:52.365--Not able to detect platform for vendor name [SQLite33.8.10.1]. Defaulting to [org.eclipse.persistence.platform.database.DatabasePlatform]. The database dialect used may not match with the database you are using. Please explicitly provide a platform using property "eclipselink.target-database".
[EL Info]: connection: 2015-08-21 16:01:52.505--ServerSession(29156874)--/file:/C:/eclipse_ee/workspaces/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/jeejpa/WEB-INF/classes/_training-jpa login successful

My application seems to work fine - do I have to care about the warning about the NullPointerException? Or do I have to care about the info?

Not able to detect platform for vendor name [SQLite33.8.10.1].
Defaulting to [org.eclipse.persistence.platform.database.DatabasePlatform].
The database dialect used may not match with the database you are using.
Please explicitly provide a platform using property "eclipselink.target-database".

EDIT: Thanks to help of @baumato and the setting <property name="eclipselink.target-database" value="Database" />the info about Not able to detect... doesn't show up any more. The detailed NullPointerException now is:

[EL Finest]: jpa: 2015-08-21 16:44:52.954--ServerSession(12993102)--Thread(Thread[http-nio-8443-exec-6,5,main])--Begin deploying Persistence Unit training-jpa; session /file:/C:/eclipse_ee/workspaces/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/jeejpa/WEB-INF/classes/_training-jpa; state Predeployed; factoryCount 1
[EL Finest]: jpa: 2015-08-21 16:44:52.964--ServerSession(12993102)--Thread(Thread[http-nio-8443-exec-6,5,main])--Bean Validation Factory was not initialized: [javax/validation/Validation].
[EL Warning]: connection: 2015-08-21 16:44:52.974--Thread(Thread[http-nio-8443-exec-6,5,main])--java.lang.NullPointerException
    at org.eclipse.persistence.platform.server.ServerPlatformUtils.createServerPlatform(ServerPlatformUtils.java:99)
    at org.eclipse.persistence.sessions.factories.SessionManager.init(SessionManager.java:77)
    at org.eclipse.persistence.sessions.factories.SessionManager.<clinit>(SessionManager.java:71)
    at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.addSessionToGlobalSessionManager(EntityManagerSetupImpl.java:907)
    at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.initSession(EntityManagerSetupImpl.java:2671)
    at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:675)
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.getAbstractSession(EntityManagerFactoryDelegate.java:205)
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.createEntityManagerImpl(EntityManagerFactoryDelegate.java:305)
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManagerImpl(EntityManagerFactoryImpl.java:337)
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:303)
    at de.training.beans.LoginBean.login(LoginBean.java:58)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:483)
    at org.apache.el.parser.AstValue.invoke(AstValue.java:247)
    at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:267)
    at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
    at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:87)
    at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
    at javax.faces.component.UICommand.broadcast(UICommand.java:315)
    at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:790)
    at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1282)
    at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:654)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at de.training.filter.URILoggerFilter.doFilter(URILoggerFilter.java:24)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at de.training.filter.LoginFilter.doFilter(LoginFilter.java:38)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:614)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
    at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:617)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:518)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1091)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:668)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1527)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1484)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Thread.java:745)

[EL Finer]: 2015-08-21 16:44:52.974--Thread(Thread[http-nio-8443-exec-6,5,main])--initializing session manager
Niklas P
  • 3,427
  • 2
  • 15
  • 19
  • You are encountering the same issue with the target server platform http://www.eclipse.org/eclipselink/documentation/2.4/jpa/extensions/p_target_server.htm – Chris Aug 24 '15 at 15:43
  • What do you mean by that? The target server platform would be the Default (`TargetServer.None`) since I'm using Tomcat. – Niklas P Aug 24 '15 at 15:53
  • Try setting it. The 'exception' occurs when it cannot find a target server class, which it catches, logs and ignores. – Chris Aug 25 '15 at 01:52

2 Answers2

5

This exception is not about database platform but about application server platform. It's not fatal. SessionManager#init() method does following:

    String platformClass
            = ServerPlatformUtils.detectServerPlatform(null);
    try {
        detectedPlatform
                = ServerPlatformUtils.createServerPlatform(
                null, platformClass,
                SessionManager.class.getClassLoader());
    } catch (NullPointerException npe) {
        //some platforms may not be handling 'null' session well,
        //so be defensive here and only log throwable here
        detectedPlatform = null;
        LOG.logThrowable(SessionLog.WARNING,
                AbstractSessionLog.CONNECTION, npe);
    }

So null is used as detected server platform and EclipseLink will consider that current application server platform does not have multitenancy support (which Apache Tomcat does not have). This code in SessionManager is related to new WebLogic feature and you may simply ignore it. 2.7.0 throws ServerPlatformException instead of NPE but this change was not bacported to 2.6.1.

If you guys would like to add Apache Tomcat platform detection, please open enhancement request on Eclipselink Bugzilla and vote for it to give it a priority.

Tomas Kraus
  • 466
  • 2
  • 6
  • This is really bad code in EclipseLink 2.6.1. NPE, no message. EclipseLink calls this method from three places potentially with null and does not give any hint what is wrong. public static ServerPlatform createServerPlatform(DatabaseSession session, String platformClass, ClassLoader loader) { if (platformClass == null) { throw new NullPointerException(); } – dmatej Nov 05 '15 at 07:08
  • Same problem is in Glassfish and Payara. The problem is that NPE is thrown before parsing of persistence.xml so there is no way to resolve it here. I will report it in bugzilla. – dmatej Nov 05 '15 at 08:47
  • OK, thanks. Please send me bug number to tomas.kraus@oracle.com I'll check what we can do with it. – Tomas Kraus Nov 06 '15 at 13:54
  • I commented this issue and attached a link to the stacktrace in Pastebin https://bugs.eclipse.org/bugs/show_bug.cgi?id=463629#c10 – dmatej Nov 10 '15 at 14:40
  • Seems like it will be fixed in 2.6.2, it's very annoying though, especially because this happens before parsing the configuration. Very bad to see static initializers like these :-( – Mauro Molinari Dec 03 '15 at 11:10
  • By the way, I somewhat contributed a Tomcat 8 Platform implementation at: https://bugs.eclipse.org/bugs/show_bug.cgi?id=457558 but it didn't get much attention. – Mauro Molinari Dec 03 '15 at 11:12
3

I would suggest to add following properties in the properties section of your persistence.xml to get detailed debug information:

<property name="eclipselink.logging.level" value="ALL" />
<property name="eclipselink.logging.level.sql" value="FINE"/>
<property name="eclipselink.logging.parameters" value="true" />
<property name="eclipselink.logging.connection" value="true" />
<property name="eclipselink.logging.session" value="true" />
<property name="eclipselink.logging.thread" value="true" />
<property name="eclipselink.logging.timestamp" value="true" />

And as the info message states, try to set the property:

<property name="eclipselink.target-database" value="Auto" />

Since "Auto" is the default, this might not help. So set the target-database to "Database". This uses a generic database, if your target database is not listed and your JDBC driver does not support the metadata required for Auto. See more at: http://www.eclipse.org/eclipselink/documentation/2.4/jpa/extensions/p_target_database.htm#sthash.y1lrDjUn.dpuf)

<property name="eclipselink.target-database" value="Database" />
baumato
  • 358
  • 3
  • 13
  • Thanks a lot. The property `target-database` set to `Database` as you proposed and which I've already updated in my original post has removed the info message about the platform. I've added the detailed NullPointerException - would be great if you can help once more. – Niklas P Aug 21 '15 at 14:55