NullPointer in log during first connection to database

前端 未结 2 813
北海茫月
北海茫月 2020-12-11 05:09

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

    <
相关标签:
2条回答
  • 2020-12-11 05:23

    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.

    0 讨论(0)
  • 2020-12-11 05:31

    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" />
    
    0 讨论(0)
提交回复
热议问题