3 Replies Latest reply on Mar 18, 2008 1:32 AM by Praveen Jain

    Seam-managed persistence contexts and Glassfish

    Praveen Jain Newbie

      Hello forum,


      I have recently been learning about Seam for my current project and one of the things I am trying to figure out is seam-managed persistence context.


      I have changed a simple hello world code to use seam-managed persistence context but I am not able to run it successfully on glassfish. I get following he error when I call getPeople() method in the ejb...


      javax.ejb.TransactionRolledbackLocalException: Exception thrown from bean; nested exception is: java.lang.IllegalArgumentException: EntityManagerFactory not found in JNDI : persistence/em
      


      Here is the code snippet from various files..


      Persistence.xml


        <persistence-unit name="test" transaction-type="JTA">
          <provider>org.hibernate.ejb.HibernatePersistence</provider>
          <jta-data-source>jdbc/Postgress</jta-data-source>
          <class>seam.entities.Person</class>
          <properties>
            <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"/>
            <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
          </properties>
        </persistence-unit>



      Code sippet from web.xml


          <persistence-unit-ref>
              <persistence-unit-ref-name>persistence/em</persistence-unit-ref-name>
              <persistence-unit-name>test</persistence-unit-name>
          </persistence-unit-ref>
          <ejb-local-ref>
              <ejb-ref-name>DataBean</ejb-ref-name>
              <ejb-ref-type>Session</ejb-ref-type>
              <local>seam.beans.DataLocal</local>
          </ejb-local-ref>
      
      


      Code snippet form component.xml


          <persistence:managed-persistence-context name="em"
                                                   auto-create="true" 
                                                   persistence-unit-jndi-name="persistence/em"/>
          
          <core:init jndi-pattern="java:comp/env/#{ejbName}" debug="false"/>



      Code snippet from the DataBean


      @Stateless
      @Name("dataBean")
      @Interceptors({org.jboss.seam.ejb.SeamInterceptor.class})
      public class DataBean implements DataLocal {
      ...
      ...
      
         @In
          private EntityManager em;
          private int countPeople;
          
          @Override
          public String getPeople() {
              em.persist(person);
              person = new Person();
              setFans((List<Person>) em.createQuery("select p from Person p").getResultList());
              return null;
          }
       
      ...
      ...
      }
      



      What else I am missing?


      Any help you can provide will be much appreciated.


      Thank You.

        • 1. Re: Seam-managed persistence contexts and Glassfish
          Jay Balunas Novice

          Take a look at the examples/jee5/booking and the /examples/jpa/glassfish configuration. 


          I'm not 100% what is going on - but these examples provide more than just a hello world app to look at.

          • 2. Re: Seam-managed persistence contexts and Glassfish
            judy guglielmin Novice

            Try using Glassfish v2.1...I had the same exception with Glassfish v2 and when I switched to 2.1, the exception disappeared.  (If I remember correctly the problem was with Glassfish and Hibernate or how Hibernate was dealing with compressed files)


            You can check out Seam and Glassfish for packaging and configuration details.


            • 3. Re: Seam-managed persistence contexts and Glassfish
              Praveen Jain Newbie

              Thanks Judy for the above link which led me to add the transaction manager in my persistence.xml file.


              I got the example working finally (on both versions of Glassfish) by doing minor modification to couple of files as follows.


              Removed persitence-unit-name tag from web.xml. This is not needed.


              Added following property in Persistence.xml


                          <property name="hibernate.transaction.manager_lookup_class" 
                                    value="org.hibernate.transaction.SunONETransactionManagerLookup" />
              



              Changed Component.xml as below


                 
                  <persistence:entity-manager-factory name="test"/>
                  
                  <persistence:managed-persistence-context name="em"
                                                    auto-create="true" 
                                                    entity-manager-factory="#{test}"/>
                  
                  <core:init jndi-pattern="java:comp/env/#{ejbName}" debug="false"/>