0

I do have an issue concerning persistence unit test with JPA.

I got an No Persistence provider for EntityManager named exception when I am running my JUnit tests. I follow the advices from this post No Persistence provider for EntityManager named but nothing seems working.

I run my unit test out of my JBOSS Application Server.

I get my EntityManager with this piece of code

   final String PERSISTENCE_UNIT_TEST = "RFIDPeopleProtoPersistenceTest";

   public PersonDAOTest( ) throws Exception{
    try{
        this.personDAO = new PersonDAO( );

        EntityManagerFactory factory = Persistence.createEntityManagerFactory( PERSISTENCE_UNIT_TEST );
            EntityManager em = factory.createEntityManager();  

            dao.setEntityManager( em );

    }catch( Exception e ){
        ...
    }
}

I had the hibernate-entitymanger.jar in my maven project (pom.xml)

        <dependency>
          <groupId>org.hibernate</groupId>
          <artifactId>hibernate-entitymanager</artifactId>
          <version>4.2.18.Final-redhat-2</version>
          <scope>test</scope>
    </dependency>

I had the in my persistence specification file (test-persistence.xml) for my test

<persistence-unit name="RFIDPeopleProtoPersistenceTest" transaction-type="RESOURCE_LOCAL">
  <provider>org.hibernate.ejb.HibernatePersistence</provider>
  <jta-data-source>java:jboss/datasources/rfidpeopleProtoTestDS</jta-data-source>
  <class>org.rfidpeople.prototype.model.AbstractContactInfo</class>
  <properties>
    <property name="connection.driver_class" value="net.sourceforge.jtds.jdbc.Driver" />
    <property name="connection.url" value="jdbc:jtds:sqlserver://localhost:1433/RFIDPeople" />
   <property name="connection.username" value="sa" />
   <property name="connection.password" value="sa1234" />
   <property name="dialect" value="org.hibernate.dialect.SQLServerDialect" />
   <property name="hibernate.hbm2ddl.auto" value="create-drop" />
   <property name="hibernate.show_sql" value="false" />  
  </properties>

I have this file system in my eclipse JBOSS developer studio

project file system

I am currently out of solutions to find my problem.

I bit help will be appreciated.

DHS
  • 1
  • Try putting the persistence.xml in the test resources META-INF maybe. Or are you replacing the original persistence.xml with test-persistence.xml via arquillian? – noone Nov 07 '15 at 09:28
  • hi, thanks a lot for answering actually I have a test-persistence.xml in src/test/resources/META-INF. The persistence unit described above is contained in the test-persistence.xml – DHS Nov 08 '15 at 15:37
  • JPA doesn't look for test-persistence.xml. Unless it is renamed to persistence.xml via arquillian, it's not going to be used at all. Might explain why the persistence unit doesn't exist. – noone Nov 08 '15 at 16:30
  • it's ok now. thanks a lot. – DHS Nov 14 '15 at 10:33

0 Answers0