我正在学习Java EE,我目前正在尝试使用带有Tomee服务器的derby数据库。
我在(tomee-path)/conf/tomee.xml中声明了我的数据源,如下所示:
<Resource id="IsiDrive" type="DataSource">
JdbcDriver = org.apache.derby.jdbc.EmbeddedDriver
JdbcUrl = jdbc:derby://localhost:1527/isidrive
JtaManaged true
</Resource>
位于(project-path)/src/META-INF/persistence.xml中的persistence.xml文件包含以下内容:
<?xml version="1.0" encoding="UTF-8"?>
<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="IsiDrive">
<provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
<jta-data-source>IsiDrive</jta-data-source>
<class>model.Banana</class>
</persistence-unit>
当我启动服务器并尝试使用简单方法访问数据库时:
public class Controller {
@PersistenceContext(unitName = "IsiDrive")
EntityManager em;
public void test() {
Query q = em.createQuery("SELECT u FROM Banana u");
List<Banana> userList = q.getResultList(); //error
}
}
我收到了以下日志:
Starting OpenJPA 2.3.0-nonfinal-1540826
Using dictionary class "org.apache.openjpa.jdbc.sql.HSQLDictionary" (HSQL Database Engine 2.3.0 ,HSQL Database Engine Driver 2.3.0).
Connected to HSQL Database Engine version 2.2 using JDBC driver HSQL Database Engine Driver version 2.3.0.2
PM org.apache.openejb.core.transaction.EjbTransactionUtil handleSystemException
EjbTransactionUtil.handleSystemException: user lacks privilege or object not found: BANANA {SELECT t0.id, t0.title FROM Banana t0} [code=-5501, state=42501]
<openjpa-2.3.0-nonfinal-1540826-r422266:1542644 fatal general error> org.apache.openjpa.persistence.PersistenceException: user lacks privilege or object not found: BANANA {SELECT t0.id, t0.title FROM Banana t0} [code=-5501, state=42501]
FailedObject: SELECT u FROM Banana u [java.lang.String]
我不明白为什么Tomee会尝试使用HSQL,因为我想使用Derby并声明我的数据源呢?
编辑:即使我尝试使用HSQL DB或MYSQL,也会发生错误。它总是一样的。
答案 0 :(得分:2)
好的,没关系。我不应该将数据源放在(tomEE-path)/conf/tomee.xml
中,而应放在(myworkspace-path)/Servers/Tomcat v7.0 Server at localhost-config/tomee.xml
中。
愚蠢的错误,Eclipse和TomEE都没有生成关于persistence.xml
中无法找到的数据源的错误...
答案 1 :(得分:0)
检查您的日志&#34;自动调整#34;信息,它可以帮助您解决问题