我有一个使用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