jndi与jpa和eclipselink的数据库连接
我尝试在 Tomcat 5.5 上使用 JNDI 结合 eclipseLink/JPA 在 java 中设置数据库连接。我已经在 web.xml 和 context.xml 中配置了 JNDI 资源。
数据库连接使用 JNDI,无需使用 JPA 和 eclipseLink。 为 eclipseLink 配置 persistence.xml 后,出现以下异常。
我不知道如何正确配置 persistence.xml 以使用 JNDI 数据源进行数据库连接。
异常
WicketMessage: Method onFormSubmitted of interface
org.apache.wicket.markup.html.form.IFormSubmitListener targeted at component
[MarkupContainer [Component id = loginForm]] threw an exception
Root cause:
javax.naming.NamingException: This context must be accessed throught a java: URL
at org.apache.naming.SelectorContext.parseName(SelectorContext.java:686)
at org.apache.naming.SelectorContext.lookup(SelectorContext.java:121)
at javax.naming.InitialContext.lookup(InitialContext.java:396)
at org.eclipse.persistence.sessions.JNDIConnector.connect(JNDIConnector.java:110)
at org.eclipse.persistence.sessions.JNDIConnector.connect(JNDIConnector.java:94)
at org.eclipse.persistence.sessions.DatasourceLogin.connectToDatasource(DatasourceLogin.java:16 2)
at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.loginAndDetectDatasource(Datab aseSessionImpl.java:579)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryProvider.login(EntityManagerFactoryProvider.java:228)
at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:380)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.getServerSession(EntityManagerFactoryImpl.java:157)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManagerImpl(EntityManagerFactoryImpl.java:214)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:202)
at de.company.myDs.controller.AbstractCrudController.getEntityManager(Unknown Source)
at de.company.myDs.controller.UserController.loadUserByName(Unknown Source)
at de.company.myDs.controller.LoginController.validateUserLogin(Unknown Source)
at de.company.myDs.pages.LoginPage$1.onSubmit(Unknown Source)
at org.apache.wicket.markup.html.form.Form.delegateSubmit(Form.java:1534)
at org.apache.wicket.markup.html.form.Form.process(Form.java:934)
at org.apache.wicket.markup.html.form.Form.onFormSubmitted(Form.java:896)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.wicket.RequestListenerInterface.invoke(RequestListenerInterface.java:182)
at org.apache.wicket.request.target.component.listener.ListenerInterfaceRequestTarget.processEvents(ListenerInterfaceRequestTarget.java:73)
at org.apache.wicket.request.AbstractRequestCycleProcessor.processEvents(AbstractRequestCycleProcessor.java:92)
at org.apache.wicket.RequestCycle.processEventsAndRespond(RequestCycle.java:1250)
at org.apache.wicket.RequestCycle.step(RequestCycle.java:1329)
at org.apache.wicket.RequestCycle.steps(RequestCycle.java:1428)
at org.apache.wicket.RequestCycle.request(RequestCycle.java:545)
at org.apache.wicket.protocol.http.WicketFilter.doGet(WicketFilter.java:479)
at org.apache.wicket.protocol.http.WicketFilter.doFilter(WicketFilter.java:312)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:172)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:873)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)
at java.lang.Thread.run(Thread.java:637)
Complete stack:
org.apache.wicket.WicketRuntimeException: Method onFormSubmitted of interface org.apache.wicket.markup.html.form.IFormSubmitListener targeted at component [MarkupContainer [Component id = loginForm]] threw an exception
at org.apache.wicket.RequestListenerInterface.invoke(RequestListenerInterface.java:193)
at org.apache.wicket.request.target.component.listener.ListenerInterfaceRequestTarget.processEvents(ListenerInterfaceRequestTarget.java:73)
at org.apache.wicket.request.AbstractRequestCycleProcessor.processEvents(AbstractRequestCycleProcessor.java:92)
at org.apache.wicket.RequestCycle.processEventsAndRespond(RequestCycle.java:1250)
at org.apache.wicket.RequestCycle.step(RequestCycle.java:1329)
at org.apache.wicket.RequestCycle.steps(RequestCycle.java:1428)
at org.apache.wicket.RequestCycle.request(RequestCycle.java:545)
at org.apache.wicket.protocol.http.WicketFilter.doGet(WicketFilter.java:479)
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.wicket.RequestListenerInterface.invoke(RequestListenerInterface.java:182)
at org.apache.wicket.request.target.component.listener.ListenerInterfaceRequestTarget.processEvents(ListenerInterfaceRequestTarget.java:73)
at org.apache.wicket.request.AbstractRequestCycleProcessor.processEvents(AbstractRequestCycleProcessor.java:92)
at org.apache.wicket.RequestCycle.processEventsAndRespond(RequestCycle.java:1250)
at org.apache.wicket.RequestCycle.step(RequestCycle.java:1329)
at org.apache.wicket.RequestCycle.steps(RequestCycle.java:1428)
at org.apache.wicket.RequestCycle.request(RequestCycle.java:545)
at org.apache.wicket.protocol.http.WicketFilter.doGet(WicketFilter.java:479)
javax.persistence.PersistenceException: Exception [EclipseLink-7060] (Eclipse Persistence Services - 2.1.0.v20100614-r7608): org.eclipse.persistence.exceptions.ValidationException
Exception Description: Cannot acquire data source [java:comp/env/jdbc/myDs].
Internal Exception: javax.naming.NamingException: This context must be accessed throught a java: URL
at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:408)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.getServerSession(EntityManagerFactoryImpl.java:157)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManagerImpl(EntityManagerFactoryImpl.java:214)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:202)
at de.company.myDs.controller.AbstractCrudController.getEntityManager(Unknown Source)
at de.company.myDs.controller.UserController.loadUserByName(Unknown Source)
at de.company.myDs.controller.LoginController.validateUserLogin(Unknown Source)
at de.company.myDs.pages.LoginPage$1.onSubmit(Unknown Source)
at org.apache.wicket.markup.html.form.Form.delegateSubmit(Form.java:1534)
at org.apache.wicket.markup.html.form.Form.process(Form.java:934)
at org.apache.wicket.markup.html.form.Form.onFormSubmitted(Form.java:896)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.wicket.RequestListenerInterface.invoke(RequestListenerInterface.java:182)
at org.apache.wicket.request.target.component.listener.ListenerInterfaceRequestTarget.processEvents(ListenerInterfaceRequestTarget.java:73)
at org.apache.wicket.request.AbstractRequestCycleProcessor.processEvents(AbstractRequestCycleProcessor.java:92)
at org.apache.wicket.RequestCycle.processEventsAndRespond(RequestCycle.java:1250)
at org.apache.wicket.RequestCycle.step(RequestCycle.java:1329)
at org.apache.wicket.RequestCycle.steps(RequestCycle.java:1428)
at org.apache.wicket.RequestCycle.request(RequestCycle.java:545)
at org.apache.wicket.protocol.http.WicketFilter.doGet(WicketFilter.java:479)
Exception [EclipseLink-7060] (Eclipse Persistence Services - 2.1.0.v20100614-r7608): org.eclipse.persistence.exceptions.ValidationException
Exception Description: Cannot acquire data source [java:comp/env/jdbc/myDs].
Internal Exception: javax.naming.NamingException: This context must be accessed throught a java: URL
at org.eclipse.persistence.exceptions.ValidationException.cannotAcquireDataSource(ValidationException.java:464)
at org.eclipse.persistence.sessions.JNDIConnector.connect(JNDIConnector.java:116)
at org.eclipse.persistence.sessions.JNDIConnector.connect(JNDIConnector.java:94)
at org.eclipse.persistence.sessions.DatasourceLogin.connectToDatasource(DatasourceLogin.java:162)
at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.loginAndDetectDatasource(DatabaseSessionImpl.java:579)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryProvider.login(EntityManagerFactoryProvider.java:228)
at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:380)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.getServerSession(EntityManagerFactoryImpl.java:157)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManagerImpl(EntityManagerFactoryImpl.java:214)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:202)
at de.company.myDs.controller.AbstractCrudController.getEntityManager(Unknown Source)
at de.company.myDs.controller.UserController.loadUserByName(Unknown Source)
at de.company.myDs.controller.LoginController.validateUserLogin(Unknown Source)
at de.company.myDs.pages.LoginPage$1.onSubmit(Unknown Source)
at org.apache.wicket.markup.html.form.Form.delegateSubmit(Form.java:1534)
at org.apache.wicket.markup.html.form.Form.process(Form.java:934)
at org.apache.wicket.markup.html.form.Form.onFormSubmitted(Form.java:896)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.wicket.RequestListenerInterface.invoke(RequestListenerInterface.java:182)
at org.apache.wicket.request.target.component.listener.ListenerInterfaceRequestTarget.processEvents(ListenerInterfaceRequestTarget.java:73)
at org.apache.wicket.request.AbstractRequestCycleProcessor.processEvents(AbstractRequestCycleProcessor.java:92)
at org.apache.wicket.RequestCycle.processEventsAndRespond(RequestCycle.java:1250)
at org.apache.wicket.RequestCycle.step(RequestCycle.java:1329)
at org.apache.wicket.RequestCycle.steps(RequestCycle.java:1428)
at org.apache.wicket.RequestCycle.request(RequestCycle.java:545)
at org.apache.wicket.protocol.http.WicketFilter.doGet(WicketFilter.java:479)
web.xml
...
<resource-ref>
<description>DB Connection</description>
<res-ref-name>jdbc/myDs</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
...
context.xml
...
<Resource
name="jdbc/myDs"
auth="Container"
type="javax.sql.DataSource"
maxActive="100"
maxIdle="30"
validationQuery="SELECT 1"
testOnBorrow="true"
testWhileIdle="true"
timeBetweenEvictionRunsMillis="60000"
minEvictableIdleTimeMillis="600000"
username="root"
password="passwd"
maxWait="10000"
driverClassName="org.postgresql.Driver"
url="jdbc:postgresql://localhost:5432/myDs" />
...
persistence.xml
...
<persistence-unit name="myDs" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<non-jta-data-source>java:comp/env/jdbc/myDs</non-jta-data-source>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<class>de.company.myDS.model.User</class>
</persistence-unit>
...
I try to setup a database connection in java with JNDI in combination with eclipseLink/JPA on Tomcat 5.5. I already configured the JNDI resource in web.xml and context.xml.
The db connection works with JNDI without using JPA and eclipseLink.
After configuring the persistence.xml for eclipseLink, I got the following exception.
I don't know how to configure the persistence.xml correctly to use JNDI datasource for the db connection.
The exception
WicketMessage: Method onFormSubmitted of interface
org.apache.wicket.markup.html.form.IFormSubmitListener targeted at component
[MarkupContainer [Component id = loginForm]] threw an exception
Root cause:
javax.naming.NamingException: This context must be accessed throught a java: URL
at org.apache.naming.SelectorContext.parseName(SelectorContext.java:686)
at org.apache.naming.SelectorContext.lookup(SelectorContext.java:121)
at javax.naming.InitialContext.lookup(InitialContext.java:396)
at org.eclipse.persistence.sessions.JNDIConnector.connect(JNDIConnector.java:110)
at org.eclipse.persistence.sessions.JNDIConnector.connect(JNDIConnector.java:94)
at org.eclipse.persistence.sessions.DatasourceLogin.connectToDatasource(DatasourceLogin.java:16 2)
at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.loginAndDetectDatasource(Datab aseSessionImpl.java:579)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryProvider.login(EntityManagerFactoryProvider.java:228)
at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:380)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.getServerSession(EntityManagerFactoryImpl.java:157)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManagerImpl(EntityManagerFactoryImpl.java:214)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:202)
at de.company.myDs.controller.AbstractCrudController.getEntityManager(Unknown Source)
at de.company.myDs.controller.UserController.loadUserByName(Unknown Source)
at de.company.myDs.controller.LoginController.validateUserLogin(Unknown Source)
at de.company.myDs.pages.LoginPage$1.onSubmit(Unknown Source)
at org.apache.wicket.markup.html.form.Form.delegateSubmit(Form.java:1534)
at org.apache.wicket.markup.html.form.Form.process(Form.java:934)
at org.apache.wicket.markup.html.form.Form.onFormSubmitted(Form.java:896)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.wicket.RequestListenerInterface.invoke(RequestListenerInterface.java:182)
at org.apache.wicket.request.target.component.listener.ListenerInterfaceRequestTarget.processEvents(ListenerInterfaceRequestTarget.java:73)
at org.apache.wicket.request.AbstractRequestCycleProcessor.processEvents(AbstractRequestCycleProcessor.java:92)
at org.apache.wicket.RequestCycle.processEventsAndRespond(RequestCycle.java:1250)
at org.apache.wicket.RequestCycle.step(RequestCycle.java:1329)
at org.apache.wicket.RequestCycle.steps(RequestCycle.java:1428)
at org.apache.wicket.RequestCycle.request(RequestCycle.java:545)
at org.apache.wicket.protocol.http.WicketFilter.doGet(WicketFilter.java:479)
at org.apache.wicket.protocol.http.WicketFilter.doFilter(WicketFilter.java:312)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:172)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:873)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)
at java.lang.Thread.run(Thread.java:637)
Complete stack:
org.apache.wicket.WicketRuntimeException: Method onFormSubmitted of interface org.apache.wicket.markup.html.form.IFormSubmitListener targeted at component [MarkupContainer [Component id = loginForm]] threw an exception
at org.apache.wicket.RequestListenerInterface.invoke(RequestListenerInterface.java:193)
at org.apache.wicket.request.target.component.listener.ListenerInterfaceRequestTarget.processEvents(ListenerInterfaceRequestTarget.java:73)
at org.apache.wicket.request.AbstractRequestCycleProcessor.processEvents(AbstractRequestCycleProcessor.java:92)
at org.apache.wicket.RequestCycle.processEventsAndRespond(RequestCycle.java:1250)
at org.apache.wicket.RequestCycle.step(RequestCycle.java:1329)
at org.apache.wicket.RequestCycle.steps(RequestCycle.java:1428)
at org.apache.wicket.RequestCycle.request(RequestCycle.java:545)
at org.apache.wicket.protocol.http.WicketFilter.doGet(WicketFilter.java:479)
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.wicket.RequestListenerInterface.invoke(RequestListenerInterface.java:182)
at org.apache.wicket.request.target.component.listener.ListenerInterfaceRequestTarget.processEvents(ListenerInterfaceRequestTarget.java:73)
at org.apache.wicket.request.AbstractRequestCycleProcessor.processEvents(AbstractRequestCycleProcessor.java:92)
at org.apache.wicket.RequestCycle.processEventsAndRespond(RequestCycle.java:1250)
at org.apache.wicket.RequestCycle.step(RequestCycle.java:1329)
at org.apache.wicket.RequestCycle.steps(RequestCycle.java:1428)
at org.apache.wicket.RequestCycle.request(RequestCycle.java:545)
at org.apache.wicket.protocol.http.WicketFilter.doGet(WicketFilter.java:479)
javax.persistence.PersistenceException: Exception [EclipseLink-7060] (Eclipse Persistence Services - 2.1.0.v20100614-r7608): org.eclipse.persistence.exceptions.ValidationException
Exception Description: Cannot acquire data source [java:comp/env/jdbc/myDs].
Internal Exception: javax.naming.NamingException: This context must be accessed throught a java: URL
at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:408)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.getServerSession(EntityManagerFactoryImpl.java:157)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManagerImpl(EntityManagerFactoryImpl.java:214)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:202)
at de.company.myDs.controller.AbstractCrudController.getEntityManager(Unknown Source)
at de.company.myDs.controller.UserController.loadUserByName(Unknown Source)
at de.company.myDs.controller.LoginController.validateUserLogin(Unknown Source)
at de.company.myDs.pages.LoginPage$1.onSubmit(Unknown Source)
at org.apache.wicket.markup.html.form.Form.delegateSubmit(Form.java:1534)
at org.apache.wicket.markup.html.form.Form.process(Form.java:934)
at org.apache.wicket.markup.html.form.Form.onFormSubmitted(Form.java:896)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.wicket.RequestListenerInterface.invoke(RequestListenerInterface.java:182)
at org.apache.wicket.request.target.component.listener.ListenerInterfaceRequestTarget.processEvents(ListenerInterfaceRequestTarget.java:73)
at org.apache.wicket.request.AbstractRequestCycleProcessor.processEvents(AbstractRequestCycleProcessor.java:92)
at org.apache.wicket.RequestCycle.processEventsAndRespond(RequestCycle.java:1250)
at org.apache.wicket.RequestCycle.step(RequestCycle.java:1329)
at org.apache.wicket.RequestCycle.steps(RequestCycle.java:1428)
at org.apache.wicket.RequestCycle.request(RequestCycle.java:545)
at org.apache.wicket.protocol.http.WicketFilter.doGet(WicketFilter.java:479)
Exception [EclipseLink-7060] (Eclipse Persistence Services - 2.1.0.v20100614-r7608): org.eclipse.persistence.exceptions.ValidationException
Exception Description: Cannot acquire data source [java:comp/env/jdbc/myDs].
Internal Exception: javax.naming.NamingException: This context must be accessed throught a java: URL
at org.eclipse.persistence.exceptions.ValidationException.cannotAcquireDataSource(ValidationException.java:464)
at org.eclipse.persistence.sessions.JNDIConnector.connect(JNDIConnector.java:116)
at org.eclipse.persistence.sessions.JNDIConnector.connect(JNDIConnector.java:94)
at org.eclipse.persistence.sessions.DatasourceLogin.connectToDatasource(DatasourceLogin.java:162)
at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.loginAndDetectDatasource(DatabaseSessionImpl.java:579)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryProvider.login(EntityManagerFactoryProvider.java:228)
at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:380)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.getServerSession(EntityManagerFactoryImpl.java:157)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManagerImpl(EntityManagerFactoryImpl.java:214)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:202)
at de.company.myDs.controller.AbstractCrudController.getEntityManager(Unknown Source)
at de.company.myDs.controller.UserController.loadUserByName(Unknown Source)
at de.company.myDs.controller.LoginController.validateUserLogin(Unknown Source)
at de.company.myDs.pages.LoginPage$1.onSubmit(Unknown Source)
at org.apache.wicket.markup.html.form.Form.delegateSubmit(Form.java:1534)
at org.apache.wicket.markup.html.form.Form.process(Form.java:934)
at org.apache.wicket.markup.html.form.Form.onFormSubmitted(Form.java:896)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.wicket.RequestListenerInterface.invoke(RequestListenerInterface.java:182)
at org.apache.wicket.request.target.component.listener.ListenerInterfaceRequestTarget.processEvents(ListenerInterfaceRequestTarget.java:73)
at org.apache.wicket.request.AbstractRequestCycleProcessor.processEvents(AbstractRequestCycleProcessor.java:92)
at org.apache.wicket.RequestCycle.processEventsAndRespond(RequestCycle.java:1250)
at org.apache.wicket.RequestCycle.step(RequestCycle.java:1329)
at org.apache.wicket.RequestCycle.steps(RequestCycle.java:1428)
at org.apache.wicket.RequestCycle.request(RequestCycle.java:545)
at org.apache.wicket.protocol.http.WicketFilter.doGet(WicketFilter.java:479)
web.xml
...
<resource-ref>
<description>DB Connection</description>
<res-ref-name>jdbc/myDs</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
...
context.xml
...
<Resource
name="jdbc/myDs"
auth="Container"
type="javax.sql.DataSource"
maxActive="100"
maxIdle="30"
validationQuery="SELECT 1"
testOnBorrow="true"
testWhileIdle="true"
timeBetweenEvictionRunsMillis="60000"
minEvictableIdleTimeMillis="600000"
username="root"
password="passwd"
maxWait="10000"
driverClassName="org.postgresql.Driver"
url="jdbc:postgresql://localhost:5432/myDs" />
...
persistence.xml
...
<persistence-unit name="myDs" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<non-jta-data-source>java:comp/env/jdbc/myDs</non-jta-data-source>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<class>de.company.myDS.model.User</class>
</persistence-unit>
...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
只需将类
JPAEclipseLinkSessionCustomizer
添加到您的项目中并配置 persistence.xml,如下所示:仅对于 Apache Tomcat,您需要此解决方法。
Just add the class
JPAEclipseLinkSessionCustomizer
to your project and configure the persistence.xml as shown below:You need this workaround only for Apache Tomcat.
将数据源 URL 设置为“jdbc/myDs”
<非jta数据源>jdbc/myDs
Set the datasource URL to "jdbc/myDs"
<non-jta-data-source>jdbc/myDs</non-jta-data-source>
我希望您可以通过给出的注释解决问题...
我通过添加与元素
non-jta-data-source
具有相同值的属性“javax.persistence.nonJtaDataSource”来修复它I hope you could solve the problem with the comments given ...
I fix it by adding a property "javax.persistence.nonJtaDataSource" with the same value as the element
non-jta-data-source
我认为您需要为
javax.naming.NamingException: This context must be accesst through a java: URL
异常编写一个解决方法,详细信息请参阅 http://wiki.eclipse.org/EclipseLink/Examples/JPA/Tomcat_Web_Tutorial#Session_Customizer另请参阅此链接,该链接通过问题
http://forums.java.net/jive/message.jspa?messageID =158622
I think you need to code a workaround for the
javax.naming.NamingException: This context must be accessed throught a java: URL
exception as detailed at http://wiki.eclipse.org/EclipseLink/Examples/JPA/Tomcat_Web_Tutorial#Session_CustomizerAlso see this link which debugs through the problem
http://forums.java.net/jive/message.jspa?messageID=158622
2015 年实现:我不确定是否需要 Eclipselink SessionCustomizer。在我的测试中,所有这些都不需要(Tomcat 7.x、Java 7.x、Eclipselink 2.4.x)。
一些较旧的材料提出了 Tomcat 5/6 的具体问题以及解决该问题的特殊方法。
Year 2015 actualisation: I not sure Eclipselink SessionCustomizer is required. In my test all work without (Tomcat 7.x, Java 7.x, Eclipselink 2.4.x).
Some older materials suggest specific problem with Tomcat 5/6 and special way to resolve it.