2 Replies Latest reply on Jul 4, 2011 6:17 AM by gg cc

    Testing persistence Resource Local in Junit in JBoss 6

    gg cc Newbie

      Hi all,


      I would like to run some Junit tests in my project in JBoss 6 with my Resouce Local Persistence Unit.




      <persistence-unit name="db-test" transaction-type="RESOURCE_LOCAL">





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

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

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

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

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

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

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

                  <property name="hibernate.search.default.directory_provider" value="filesystem" />

                  <property name="hibernate.search.default.indexBase" value="/var/lucene/testindexes" />






      And here is my junit test:



      public class PersistenceUnitTest



          static private final String PERSISTENCE_UNIT_NAME = "db-test";

          private EntityManager entityManager;



          public void setUp()


              entityManager = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME).createEntityManager();




          public void tearDown()






          public void testPersistence()







      When i try to run the test, i got an exception:


      java.lang.RuntimeException: You have not defined a non-jta-data-source for a RESOURCE_LOCAL enabled persistence context named...


      Then, I defined a non-jta-data-source in jboss and I add <non-jta-data-source>java:/TestDS</non-jta-data-source> to my persistence.xml. First question, why would i need to create this in jboss if i only want to run the test?


      Then i had more problems with jndi...i had to add jndi.properties...i now i don't really know what i have to do..


      can anybody tell me how to run a test with a resource local persistence?