我正在学习Java EE,目前正在尝试将Tomby服务器与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,也会发生错误。而且总是一样的。

最佳答案

好的不要紧。我不应该将数据源放在(tomEE-path)/conf/tomee.xml中,而应该放在(myworkspace-path)/Servers/Tomcat v7.0 Server at localhost-config/tomee.xml中。
愚蠢的错误,Eclipse和TomEE都不会在persistence.xml中生成关于数据源的错误,但找不到。

关于jakarta-ee - TomEE和数据源:用户缺少特权或找不到对象,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/22642971/

10-10 07:57