[英]HibernatePersistence javax.naming.NameNotFoundException thrown with DataSource
I am building a Tomcat Servlet application using Hibernate with a jta data source. 我正在使用带有jta数据源的Hibernate构建Tomcat Servlet应用程序。 My persistence.xml has the following content:
我的persistence.xml具有以下内容:
<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="metadata.model" transaction-type="JTA">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>jdbc/BitronixJTADataSource</jta-data-source>
...
</persistence>
In my ${web-app}/WebContent/META-INF/Context.xml
, I have the following content: 在我的
${web-app}/WebContent/META-INF/Context.xml
,我具有以下内容:
<Context>
<Resource name="jdbc/BitronixJTADataSource" auth="Container"
type="javax.sql.DataSource"
maxActive="100" maxIdle="30" maxWait="10000"
username="root" password="mysecretpassword"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/metadatadb" />
</Context>
Right after the application is started, I issue: 在应用程序启动后,我立即发出:
emf = Persistence.createEntityManagerFactory("metadata.model");
entityManager = emf.createEntityManager();
and get a 并得到一个
javax.naming.NameNotFoundException: Name [jdbc/BitronixJTADataSource] is not bound in this Context. Unable to find [jdbc].
Do you have any idea why this is occuring? 您知道为什么会这样吗?
似乎在persistence.xml中, jta-data-source
应该具有java:comp/env/jdbc/BitronixJTADataSource
值,以便在InitialContext中找到它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.