9 Replies Latest reply on Dec 21, 2007 2:20 AM by sushmu

    TestNG entityMnager question

    Daniel Kane Novice

      Hello
      First time using TestNG with Seam components.

      Test class :

      public class SimpleSearchCase extends SeamTest
      {
       EntityManager em;
      
       @BeforeClass
       public void initEm() throws Exception
       {
       EntityManagerFactory emf =
       Persistence.createEntityManagerFactory("trackUnit");
       em = emf.createEntityManager();
       }
       .....
      


      I am running test from Eclipse .
      The project filesystem contains persistence.xml placed relatively in resources/META-INF/

      The output :


      FAILED CONFIGURATION: @BeforeClass initEm
      javax.persistence.PersistenceException: No Persistence provider for EntityManager named trackUnit
       at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:55)
       at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:33)
       at com.avtohouse.test.SimpleSearchCase.initEm(SimpleSearchCase.java:20)
      ... Removed 22 stack frames
      SKIPPED: simpleSearch


      How can I point persistence unit to TestNG ?

      Thanks

      P.S. Ant and seam-gen are not used.





        • 1. Re: TestNG entityMnager question
          Pete Muir Master

          Make sure resources is on the test classpath.

          • 2. Re: TestNG entityMnager question
            Daniel Kane Novice

             

            "pete.muir@jboss.org" wrote:
            Make sure resources is on the test classpath.


            Yes, they are in Run.. , "Classpath" tab here
            http://testng.org/pictures/launch.png

            The same output.

            • 3. Re: TestNG entityMnager question
              Pete Muir Master

              Sorry, didn't read your post carefully. I don't see why you need to init the entity manager in the Java SE fashion if you are using SeamTest.

              • 4. Re: TestNG entityMnager question
                Daniel Kane Novice

                I need to test Seam component that uses EntityManager. My test is based on "Simplicity and power beyond Java EE" book example :

                public class HelloWorldTest extends SeamTest
                {
                
                @Test
                public void unitTestSayHello() throws Exception
                {
                 Manager manager = new ManagerAction ();
                 EntityManagerFactory emf =
                 Persistence.createEntityManagerFactory("helloworld");
                 EntityManager em = emf.createEntityManager();
                 setField(manager, "em", em);
                 Person person = new Person ();
                 person.setName ("Thomas Heute");
                 setField(manager, "person", person);
                 setField(manager, "confirmed", false);
                


                The only difference in my case is initializing EntityManager in @BeforeClass method to use it in different @Test methods then.

                What is incorrect ?




                • 5. Re: TestNG entityMnager question
                  Daniel Kane Novice

                   

                  "dkane" wrote:

                  The only difference in my case is initializing EntityManager in @BeforeClass method to use it in different @Test methods then.


                  Moving that to @Test method does not help, BTW.

                  • 6. Re: TestNG entityMnager question
                    Daniel Kane Novice

                    Solved by adding hibernate-entitymanager.jar to classpath , thanks to guide :
                    http://dewarim.de/wms/error/no_persistence_provider_for_entitymanager

                    It is rather difficut to collect necessary jars for TestNG + Seam, I must say. No documentation found so far.

                    • 7. Re: TestNG entityMnager question
                      Daniel Kane Novice

                      Now getting

                      java.lang.ExceptionInInitializerError
                       at org.hibernate.cfg.Configuration.reset(Configuration.java:168)
                       at org.hibernate.cfg.AnnotationConfiguration.reset(AnnotationConfiguration.java:211)
                       at org.hibernate.cfg.Configuration.<init>(Configuration.java:187)
                       at org.hibernate.cfg.Configuration.<init>(Configuration.java:191)
                       at org.hibernate.cfg.AnnotationConfiguration.<init>(AnnotationConfiguration.java:87)
                       at org.hibernate.ejb.Ejb3Configuration.<clinit>(Ejb3Configuration.java:105)
                       at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:119)
                       at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:51)
                       at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:33)
                       at com.avtohouse.test.SimpleSearchCase.simpleSearch(SimpleSearchCase.java:22)
                      Caused by: java.lang.NullPointerException
                       at org.hibernate.util.ConfigHelper.getResourceAsStream(ConfigHelper.java:144)
                       at org.hibernate.cfg.Environment.<clinit>(Environment.java:529)
                       ... 32 more
                      ... Removed 22 stack frames


                      no idea what is still missing

                      • 8. Re: TestNG entityMnager question
                        Daniel Kane Novice

                        And, the final result for today :)

                        java.lang.NoSuchMethodError: org.hibernate.cfg.AnnotationConfiguration.getReflectionManager()Lorg/hibernate/annotations/common/reflection/ReflectionManager;
                         at org.hibernate.ejb.EventListenerConfigurator.configure(EventListenerConfigurator.java:152)
                         at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:888)
                         at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:186)
                         at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:246)
                         at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:120)
                         at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:51)
                         at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:33)
                         at com.avtohouse.test.SimpleSearchCase.simpleSearch(SimpleSearchCase.java:22)
                        ... Removed 22 stack frames
                        


                        This is being thrown from line
                        EntityManagerFactory emf =
                         Persistence.createEntityManagerFactory("trackUnit");
                        



                        • 9. Re: TestNG entityMnager question
                          sushmu Newbie

                          Make sure EntityManager and Annotations versions are aligned.

                          For example, 3.2.1.GA version for both annotatios and entity manager in the jboss maven repository would fix the exception you are getting.