createEntityManager()抛出InvocationTargetException

时间:2014-09-19 08:32:14

标签: hibernate unit-testing jpa junit entitymanager

我有一个在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>
...

0 个答案:

没有答案
相关问题