8 Replies Latest reply on Nov 10, 2006 9:22 AM by kasim

    EntityManager always Null (Using Jboss,Seam)

    lara

      I have a method in a class and inside that method I am trying to access the database by using the EntiyManager. I declared the following:
      @In(create=true)
      private EntityManager entityManager;
      I am always getting a NullPointerException when I try printing the value entityManager inside the method, I mean that the value is null for entityManager.
      In this class, no annotations are specified whether stateful or stateless, no scope is specified. Does this matter to access the EntityManager? I made sure of the persistence.xml and it is correct. So what could the problem be? It seems the injection is not working. Any help would be highly appreciated. Thanks in advance!

        • 1. Re: EntityManager always Null (Using Jboss,Seam)
          kasim


          thats not really the way you set the entity manager

          You need to use the persistence context annotation to create it. (extended type is optional)

          @PersistenceContext(type=EXTENDED)
          private EntityManager em;

          • 2. Re: EntityManager always Null (Using Jboss,Seam)
            pmuir

             

            "kasim" wrote:

            thats not really the way you set the entity manager

            You need to use the persistence context annotation to create it. (extended type is optional)

            @PersistenceContext(type=EXTENDED)
            private EntityManager em;


            No, lara is injecting the EntityManager in the correct fashion (when using a Seam Managed Persistence Context).

            Lara, does injecting an entity manager (using @In) work at all in your app? Do other injections work? Post components.xml please.

            • 3. Re: EntityManager always Null (Using Jboss Seam)
              lara

              Thanks for replying..
              Well yes injection works in my application. I am accessing the entityManager from a stateful session bean and it worked perfectly.

              Below is my components.xml file:

              <?xml version="1.0" encoding="utf-8"?>


              true
              bpmshell/#{ejbName}/local




              java:/bpmshellEntityManagerFactory

              • 4. Re: EntityManager always Null (Using Jboss Seam)
                lara

                Thanks for replying..
                Well yes injection works in my application. I am accessing the entityManager from a stateful session bean and it worked perfectly.

                Below is my components.xml file:
                <?xml version="1.0" encoding="utf-8"?>


                true
                bpmshell/#{ejbName}/local



                java:/bpmshellEntityManagerFactory



                Thanks gain

                • 5. Re: EntityManager always Null (Using Jboss,Seam)
                  pmuir

                  Please post using [ code ] tags. Please post the class that isn't working. I take it no exceptions are thrown?

                  • 6. Re: EntityManager always Null (Using Jboss,Seam)
                    lara

                    I am extremely sorry..
                    Below is my components.xml file:

                    <?xml version="1.0" encoding="utf-8"?>
                    <components>
                     <component name="org.jboss.seam.core.init">
                     <property name="myFacesLifecycleBug">true</property>
                     <property name="jndiPattern">bpmshell/#{ejbName}/local</property>
                     </component>
                    
                    
                     <component name="entityManager" class="org.jboss.seam.core.ManagedPersistenceContext">
                     <property name="persistenceUnitJndiName">java:/bpmshellEntityManagerFactory</property>
                     </component>
                    </components>
                    


                    Regards

                    • 7. Re: EntityManager always Null (Using Jboss,Seam)
                      lara

                      By the way, I don't think it is a problem due to components.xml because as I said previously, I was able to inject the entityManager inside a stateful session bean and it worked perfectly.

                      • 8. Re: EntityManager always Null (Using Jboss,Seam)
                        kasim

                         

                        "petemuir" wrote:

                        No, lara is injecting the EntityManager in the correct fashion (when using a Seam Managed Persistence Context).

                        Lara, does injecting an entity manager (using @In) work at all in your app? Do other injections work? Post components.xml please.


                        ahhh my bad ... i didnt realize thats what she was doing at first .... i guess i read the post too fast.