gpt4 book ai didi

java - 首次连接到数据库时日志中出现 NullPointer

转载 作者:IT王子 更新时间:2023-10-29 06:25:46 26 4
gpt4 key购买 nike

我得到一个 NullPointerException在我第一次使用 createEntityManager() 连接到数据库时,在我的 tomcat 控制台上.我正在使用:

  • apache tomcat 8.0.24
  • eclipselink 2.6.1-RC1(JPA 间接使用)
  • sqlite jdbc 3.8.10.1

日志信息如下:

[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

我的应用程序似乎运行良好 - 我是否需要关心有关 NullPointerException警告?还是我必须关心信息

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".

编辑:感谢@baumato 的帮助和设置 <property name="eclipselink.target-database" value="Database" />有关无法检测... 的信息不再显示。现在详细的 NullPointerException 是:

[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

最佳答案

此异常与数据库平台无关,与应用服务器平台有关。这不是致命的。SessionManager#init() 方法执行以下操作:

    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);
}

因此 null 被用作检测到的服务器平台,EclipseLink 将认为当前应用服务器平台没有 Multi-Tenancy 支持(Apache Tomcat 没有)。SessionManager 中的这段代码与新的 WebLogic 功能相关,您可以忽略它。2.7.0 抛出 ServerPlatformException 而不是 NPE,但此更改未反射(reflect)到 2.6.1。

如果大家想添加Apache Tomcat平台检测,请打开enhancement request在 Eclipselink Bugzilla 上投票并给予它优先权。

关于java - 首次连接到数据库时日志中出现 NullPointer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32142789/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com