我有一個使用struts2和openJPA構建的項目。我想做一些集成測試,但是我似乎遇到了一個讓它工作的問題。集成測試OpenJPA數據訪問對象或服務門面?
的persistence.xml
<persistence-unit name="SalesCertIT" transaction-type="RESOURCE_LOCAL">
<jta-data-source>jdbc/salesCertIT</jta-data-source>
<class>com.ist.salesCert.entities.Certification</class>
<properties>
<property name="log4j" value="DefaultLevel=WARN, Runtime=INFO, Tool=INFO, SQL=TRACE" />
<property name="openjpa.ConnectionDriverName" value="com.mysql.jdbc.Driver" />
<property name="openjpa.ConnectionURL" value="jdbc:mysql://localhost:3306/sales_certification" />
<property name="openjpa.ConnectionUserName" value="dev" />
<property name="openjpa.ConnectionPassword" value="password" />
<property name="openjpa.Id" value="SalesCertIT" />
<property name="openjpa.ConnectionDriverName" value="org.apache.derby.jdbc.EmbeddedDriver" />
</properties>
</persistence-unit>
類:
EntityManagerFactory emf = Persistence.createEntityManagerFactory("SalesCertIT");
EntityManager em = emf.createEntityManager();
我得到的錯誤:
A JDBC Driver or DataSource class name must be specified in the ConnectionDriverName property.
我已經添加了兩個persistence.xml並使用mysql-connector-java的 - * -stable-bin-jar到類路徑中,(Eclipse-> debug Configuration-> Class路徑 - >引導條目)
如果我嘗試在運行時對其進行配置,它的工作,但後來我在嘗試進行操作時,另一個錯誤:
HashMap<String, String> conf = new HashMap<String, String>();
conf.put("openjpa.ConnectionDriverName", "com.mysql.jdbc.Driver");
conf.put("openjpa.ConnectionURL", "jdbc:mysql://localhost:3306/sales_certification");
conf.put("openjpa.ConnectionUserName", "dev");
conf.put("openjpa.ConnectionPassword", "password");
conf.put("openjpa.TransactionMode", "local");
conf.put("openjpa.Id", "SalesCertIT");
EntityManagerFactory emf = Persistence.createEntityManagerFactory("SalesCertIT", conf);
EntityManager em = emf.createEntityManager();
The type "class com.ist.salesCert.entities.Certification" has not been enhanced.
我嘗試添加javaagent參數:(Eclipse的>設置 - 調試> Arguments-> VM參數)
-javaagent:C:/Progra~1/IBM/WebSphere/AppServer/plugins/com.ibm.ws.jpa.jar
在這一點上,我不知道還有什麼嘗試。有任何想法嗎?
你想在JSE或JEE中運行這個嗎?在你的第一個配置部分,爲什麼你有多個openjpa.ConnectionDriverName屬性?當你的測試運行時,除xyz之外還有其他有意義的消息還沒有被增強嗎? – Rick 2012-03-27 14:03:08