6 Replies Latest reply on Dec 18, 2012 10:26 AM by meewan

    Seam2.3 entityManager is always NULL

    meewan

      Hello,

       

      I actuelly migrate an application from jboss 4.2.2/seam 2.1/richfaces 3.3.0 to jboss7.1.1/seam2.3.0/richfaces4.2.3  and I my entityManager is always null.

       

      After the end of the depployment of Jboss I call entitymanager with

       

        @In

        protected EntityManager     entityManager;

       

      but when I try to read it it is null.

       

      So do you have an idea to correct the problem ?

       

       

      attached documents my component.xml and persistence.xml

        • 1. Re: Seam2.3 entityManager is always NULL
          meewan

          After more researches, I think the probleme is that the class org.jboss.seam.persistence.ManagedPersistenceContext is never started but I still don't know why.

          • 2. Re: Seam2.3 entityManager is always NULL
            mmulligan03

            From what the comments read, in the JBoss AS 7 documentation, only the EntityManagerFactory is supported not the EntityManager itself. Take a look at the documentation here: https://docs.jboss.org/author/display/AS71/JPA+Reference+Guide?focusedCommentId=52035733#comment-52035733

            • 3. Re: Seam2.3 entityManager is always NULL
              meewan

              As I undestand the managerFactory is supported by seam 2.3(which targets jboss 7.1) because in the seam migration documentation (migrate from seam 2.2 to seam2.3) and the jboss documentation do not speak about this but I will try to see. thanks for your help.

              • 4. Re: Seam2.3 entityManager is always NULL
                mmulligan03

                I was able to get around it by using @PersistenceContext instead of @In.

                 

                In my case I specified the persistence unit like so:

                @PersistenceContext(unitName = "ess")

                private EntityManager entityManager;

                 

                If you use EntityQuery or EntityHome I had to overide the getEntityManager() method, here is an example:

                public class EntityFactoryHome<E> extends EntityHome<E> {

                 

                     @Override

                     public EntityManager getEntityManager() {

                             EntityManager em = null;

                             EntityManagerFactory emf;

                             try {

                                   emf = (EntityManagerFactory) InitialContext.doLookup("java:jboss/essEntityManagerFactory");

                                   if (emf != null)

                                        em = emf.createEntityManager();

                             } catch (NamingException e) {

                                   throw new IllegalStateException("EntityManagerFactory cannot create entity manager");

                             }

                             return em;

                          }

                }


                • 5. Re: Seam2.3 entityManager is always NULL
                  maschmid

                  The problem might be that you need to update the namespaces in components.xml (from xmlns:persistence="http://jboss.com/products/seam/persistence"     to   xmlns:persistence="http://jboss.org/schema/seam/persistence", etc. )   otherwise it won't  understand your persistence:managed-persistence-context definition...   that's why it may be never started.

                  • 6. Re: Seam2.3 entityManager is always NULL
                    meewan

                    Sorry to answer late.

                     

                    Marek, I tryed your solution but it didn't work.

                    Matt, your solution worked but it was to heavy to do it on my project.

                     

                    Thanks for your help.

                    Meewan

                     

                    edit 3 : Marek solution was the good one, I was just douing it wrong. thanks angain for your help