我有一个在WildFly上运行的应用程序。
我需要为DAO对象编写单元测试,并需要一个EntityManager。但是,当在EntityManagerFactory上调用createEntityManager
时,我得到一个InvocationTargetException。
测试在本地MySQL服务器上运行。
我没有想法。任何人都知道可能出错了什么?
entityManagerFactory = Persistence.createEntityManagerFactory("test_fakebookPU");
entityManager = entityManagerFactory.createEntityManager(); // InvocationTargetException
的persistence.xml
...
<!-- Persistence unit for testing ONLY-->
<persistence-unit name="test_myPU" transaction-type="JTA">
<description>
In memory example using Hibernate and HSQLDB
</description>
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<class>se.chas.fakebook.entities.Post</class>
<class>se.chas.fakebook.entities.User</class>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://127.0.0.1:3306/test_myPU"/>
<property name="javax.persistence.jdbc.user" value="testuser"/>
<property name="javax.persistence.jdbc.password" value="testpasss"/>
<property name="hibernate.hbm2ddl.auto" value="create"/>
<property name="hibernate.show_sql" value="true" />
</properties>
</persistence-unit>
...