7 Replies Latest reply on Jan 26, 2011 8:19 PM by mchisty.mchisty.gmail.com

    Seam-TestNG-JTA EntityManager cannot access a transactions

    aimee

      Eclipse 3.3.3.1, Eclipse TestNG plugin installed, JBoss Tools plugin installed; JBoss 4.2.2; Seam 2.0.0


      Using Eclipse, created a Seam Web project. Again used Eclipse to create a Seam Entity call Product (copied code from dvdstore example). Created a simple test class and copied/modified code from dvdstore ProductUnitTest class:


      public class ProductUnitTest extends SeamTest {
           private EntityManagerFactory emf = null;
           private EntityManager em = null;
           
           @Test     
           public void testCreateDelete() {
                try {
                     System.out.println("creating EntityManagerFactory and EntityManager");
                     EntityManagerFactory emf = Persistence.createEntityManagerFactory("Simple");
                     EntityManager em = emf.createEntityManager();
                     assertNotNull("entity manager", em);
                     assertTrue("entity manager open", em.isOpen());
      
                     Product p = new Product();
                     p.setTitle("test");
      
                     System.out.println("persisting Product...");
                     em.getTransaction().begin();
                     em.persist(p);
                     em.getTransaction().commit();
      
                     System.out.println("verifying product id > 0...");
                     long id = p.getProductId();
                     assertTrue("product id set", id != 0);
      
                     System.out.println("fetching Product...");
                     p = em.find(Product.class, id);
                     assertNotNull("find by id", p);
                     assertEquals("id", id, p.getProductId());
                     assertEquals("title", "test", p.getTitle());
                     
                     System.out.println("removing Product...");
                     em.getTransaction().begin();
                     em.remove(p);
                     em.getTransaction().commit();
      
                     System.out.println("verifying no Product in database...");
                     p = em.find(Product.class, id);
                     assertNull("deleted product", p);
                } catch (PersistenceException e) {
                     e.printStackTrace();
                     fail();
                } finally {
                     try {
                          if (em != null)     em.close();
                          if (emf != null) emf.close();
                     }catch(Exception e){
                          System.out.println("exception in finally block");
                          e.printStackTrace();
                     }
                }          
           }
           
      }//end of class



      Then EntityManager gets created but the code blows on 'em.getTransaction().begin();'




      [Invoker 32079775] Invoking @BeforeMethod org.jboss.seam.mock.SeamTest.begin()
      [Invoker 32079775] Invoking org.domain.Simple.test.ProductUnitTest.testCreateDelete
      creating EntityManagerFactory and EntityManager
      persisting Product...
      [Invoker 32079775] Invoking @AfterMethod org.jboss.seam.mock.SeamTest.end()
      [Invoker 32079775] Invoking @AfterClass org.jboss.seam.mock.SeamTest.cleanup()
      
      *********** INVOKED METHODS
      
           org.jboss.seam.mock.SeamTest.init() 27653945
                org.domain.Simple.test.ProductUnitTest.testCreateDelete() 27653945
           org.jboss.seam.mock.SeamTest.cleanup() 27653945
      
      ***********
      
      Creating C:\SVN\Projects\Simple-test\test-output\Simple-test\org.domain.Simple.test.ProductUnitTest.html
      FAILED: testCreateDelete
      java.lang.IllegalStateException: JTA EntityManager cannot access a transactions
           at org.hibernate.ejb.AbstractEntityManagerImpl.getTransaction(AbstractEntityManagerImpl.java:316)
           at org.domain.Simple.test.ProductUnitTest.testCreateDelete(ProductUnitTest.java:67)
      ... Removed 22 stack frames
      
      ===============================================
          org.domain.Simple.test.ProductUnitTest
          Tests run: 1, Failures: 1, Skips: 0
      ===============================================



      Any idea what's going on? What am I missing?


      My colleague and I have a week left to put together a demo/proof of concept based on an existing ASP.NET complex workflow web app. The demo has to show off the rules engine, BPM engine, Seam conversations etc in hopes of porting the stupid asp.net app to Seam. Despite studying numerous examples and reading copious amounts of documentation, we're encountering more trouble than success. Any help is greatly appreciated!!!


      aimee


        • 1. Re: Seam-TestNG-JTA EntityManager cannot access a transactions
          pmuir

          Use an integration test with the environment set up by seam-gen, much simpler!

          • 2. Re: Seam-TestNG-JTA EntityManager cannot access a transactions
            jwi.jwi.informationsdesign.de

            Sorry for sounding a bit frustrated... but, living-by-seam-gen is not an option, or is it ?


            So far, I could only find TestNG examples, testing on the JSF-level, no plain EntityManager (persistence-)Tests. Why ?


            I'm trying to get CRUD tests running for over a week now,
            this is NOT what Seam promises.


            Looking for detailed documentation about SeamTest, apart from forums, mailing lists etc. there's only the javadoc page, which tells you nothing.


            Again, all I want is test persistence and basic Seam-component funcionalitiy (like bijection with backend components, no JSF!)


            Is this possioble or not with SeamTest ?
            If not, how can EntityManager be Unit tested outside seam-gen ?

            • 3. Re: Seam-TestNG-JTA EntityManager cannot access a transactions
              borner.bradley.orner.comcast.net

              I too have been wrestling with seam for several weeks with nothing to show for it. The promise is fantastic, the demos very enticing. Jboss tools could be great if I could actually get something to actually work with JPA outside the examples. 


              For almost a full month now, I have been spinning my wheels doing experiments, reading doc, looking/copying/modifying examples, and web searching the myriad config related issues that keep me from the seam promised land.


              The biggest hurdles always seem to be configuration related - what needs to go where in which XML/DS or properties file. I have  yet to find a concise cookbook for how config files are used and what the precedence is (e.g. I've had to copy persixtence.xml files around my generated project structure, I had to copy a -DS.xml file to the Jboss server - all adhoc approaches because I couldn't actually find what the layout was supposed to be).


              I'm very close to throwing in the towel on SEAM, despite it's sex appeal. I'm trying to use Eclipse 3.3.2, w/ seam 2.0.1.GA, jbosstools 2.0.0GA, Jboss 4.2.2GA, MySQL 5 (using the 5.0.8 connector). I've gone so far as to resintall everything from scratch to ensure I met the blessed configuration.


              It took me 2 weeks to get the basic jboss-tools generated app shell to actually display. Now I'm trying to do a simple TestNG test for one my JPA classes (which is pretty simple). Following every example I can find gives me fits ala:


              FATAL [org.hibernate.connection.DatasourceConnectionProvider] Could not find datasource: java:/ridesDatasource
              java.lang.RuntimeException: PROVIDER_URL not provided in jndi.properties.  Automatic discovery not implemented yet.
                   at org.jboss.naming.JBossRemotingContextFactory.getInitialContext(JBossRemotingContextFactory.java:158)
                   at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:667)



              I realize this isn't a proper 'please help me debug this error' post, but I'm also looking for some higher level guidance with some actually tried and true eclipse/jbosstools/seam examples.


              Does such help exist or should I wait year for some maturation to settle in?


              Sorry for the rant, but I've exhausted my research time budget on SEAM and I'm very disappointed that I don't even have a simple prototype working after 4 weeks.


              Brad




              • 4. Re: Seam-TestNG-JTA EntityManager cannot access a transactions
                ljcoomber.seamframework.org.coomber.org

                This is probably a bit late but found your post whilst trying to resolve the error message JTA EntityManager cannot access a transactions. For me, the problem was that I had declared
                <transaction:entity-transaction entity-manager="#{entityManager}" />
                in components.xml which configures Seam to use the JPA EntityTransaction API, whilst I had configured JTA transactions in persistence.xml.

                • 5. Re: Seam-TestNG-JTA EntityManager cannot access a transactions
                  csaban

                  for the PROVIDER_URL error this helped me:


                  JBSEAM-2129


                  I added jboss-embedded-api.jar to the classpath.

                  • 6. Re: Seam-TestNG-JTA EntityManager cannot access a transactions
                    cwash

                    I ran into the same thing.  Check out your /resources/META-INF/persistence-test-war.xml if you used SeamGen.

                    • 7. Re: Seam-TestNG-JTA EntityManager cannot access a transactions
                      mchisty.mchisty.gmail.com

                      And look at Pete Muir; no reply yet... this is obvious because there is no good solution/example with SeamTest. It is JSF centric. We had the same experience. When they talk about seam, they promise a lot of things. But reality is different.