【发布时间】:2011-03-15 17:04:49
【问题描述】:
我对 persistence.xml 文件有以下配置:
<?xml version="1.0" encoding="UTF-8"?>
<persistence 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"
version="2.0">
<persistence-unit name="pu" transaction-type="RESOURCE_LOCAL">
<description>Persistent Unit for Entity Classes</description>
<provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
<non-jta-data-source>jdbc/mydb</non-jta-data-source>
<class>com.example.entity.BookEntity</class>
</persistence-unit>
</persistence>
以及 home.xml 文件的以下容器管理配置(保存在 ..\tomcat\conf\catalina\localhost 目录下):
<Context path="/home" antiJARLocking="true" reloadable="true">
<Resource name="jdbc/mydb" auth="Container"
type="javax.sql.DataSource"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/mydb?autoReconnect=true"
username="user"
password="password"
maxActive="10"
maxIdle="5"
maxWait="10000"
removeAbandoned="true"
removeAbandonedTimeout="60"
logAbandoned="true" />
</Context>
我尝试使用 MySQL Workbench 直接连接到数据库并且它可以工作,但我不知道为什么我无法通过上下文配置进行连接。
我正在使用 JSF 2 在 Tomcat 7 上运行该应用程序。
为什么我无法使用上述配置进行连接?如果需要,我可以发布实体、ejb 和控制器的代码。请帮忙,过去三天一直卡在这个问题上......
【问题讨论】: