0 Replies Latest reply on Mar 23, 2013 9:04 AM by Sam W

    Can't create persistence unit in test class.

    Sam W Expert

      Hi,

      I created ear project for jboss 7.2.

      In my junit test class, I can't use Persistence.createEntityManagerFactory to create an entityManager.

      This is the junit test class:

       

      public class ProductArticleFacadeTest {

         

          static EntityManagerFactory emf;

          static EntityManager em;

         

          public ProductArticleFacadeTest() {

          }

         

          @BeforeClass

          public static void setUpClass() {

              emf = Persistence.createEntityManagerFactory("TestDatePU");

              em = emf.createEntityManager();

          }


      When I execute this file, it failed at emf = Persistence.createEntityManagerFactory("TestDatePU");


      Error message is:

       

      caused error: org/hibernate/internal/util/xml/Origin

       

      Here is my persistence.xml file:

       

      <?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="TestDatePU" transaction-type="RESOURCE_LOCAL">

                          <properties>

                                    <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>

                                    <property name="hibernate.hbm2ddl.auto" value="update"/>

                                    <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>

                                    <property name="hibernate.connection.username" value="root"/>

                                    <property name="hibernate.connection.password" value="admin"/>

                              <property name="hibernate.show_sql" value="true"/>

                              <property name="hibernate.format_sql" value="true"/>

                                    <property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/testdb"/>

                          </properties>

                </persistence-unit>

      </persistence>

      But it looks like the junit test execution doesn't read this file, therefore it caused the error as I stated in the beginning.

       

      I also attach my project here for reference.

      Any suggestion is very much appreciated.

      Thanks

      Sam