我學習Java EE和我目前正在使用Derby數據庫與Tomee服務器。TomEE和數據源:用戶缺少特權或找不到對象
我宣佈我的(tomee路徑)的數據源/conf/tomee.xml這樣的:
<Resource id="IsiDrive" type="DataSource">
JdbcDriver = org.apache.derby.jdbc.EmbeddedDriver
JdbcUrl = jdbc:derby://localhost:1527/isidrive
JtaManaged true
</Resource>
,位於(項目路徑)/ 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,因爲我想用德比,並宣佈我的數據源,因爲它?
編輯:即使我嘗試使用HSQL DB或MySQL一個錯誤發生。它總是一樣的。
我不確定還有什麼問題,但是指定localhost的JDBC URL的EmbeddedDriver是錯誤的:1527 ;您應該使用ClientDriver(或切換到嵌入式JDBC URL)。 –
你說得對,我把URL改爲'jdbc:derby:isidrive; create = true'。但是它仍然使用HSQL而不是Derby。 – bagage