10 Replies Latest reply on Mar 13, 2008 5:33 AM by jbossindia

    different EntityManagerProxy at every request

    jbossindia

      I have entityManager configured in components.xml with conversation scope.


      I have a stateful session bean and injecting the entitymanater as @In.


      I am using EntityQuery object inside the SFSB and setting the entityManager in it from SFSB.


      Everything works file in listing and searching but when I click on slink for sorting/pagination then it gives EntityManager is closed


      I went through and found that EntityManagerProxy object is different with each invocation. I thought that EntityManager object will be same across the long-running conversation.


      Please suggest.

        • 1. Re: different EntityManagerProxy at every request
          pmuir

          Post code.

          • 2. Re: different EntityManagerProxy at every request
            jbossindia

            Here is the code...


            <persistence:managed-persistence-context auto-create="true"
            
              name="entityManager" persistence-unit-jndi-name="java:/TPEntityManagerFactory" scope="CONVERSATION" />
            
            
            
            


            
            SFSB
            
            
            @Stateful
            
            @Name("myList")
            
            @Scope(ScopeType.CONVERSATION)
            
            public class MyList extends ListImpl<MyEntity, Integer> implements List<MyEntity> {
            
                 
            
            
                 //Persistence Context injected from conversation     
            
                 @In
            
                 EntityManager entityManager;
            
            
                 public EntityManager getEntityManager() {
            
                      return entityManager;
            
                 }
            
            }
            
            



            @Scope(ScopeType.CONVERSATION)
            
            public abstract class ListImpl<E, PK> {
            
                 
            
                 //SeamFramework object to facilitate listing and pagination
            
                 EntityQuery<E> queryManager =new EntityQuery<E>();
            
                 
            
                 Pagination<E> pagination=new Pagination<E>(queryManager);
            
            
                 public void initialize() {     
            
                      queryManager.setEjbql(getEjbql());
            
                      queryManager.setRestrictions(getRestrictions());
            
                      queryManager.setEntityManager(getEntityManager());     
            
                      queryManager.setMaxResults(getMaxResults());          
            
                 }
            
            }
            
            

            • 3. Re: different EntityManagerProxy at every request
              pmuir

              Why not just let Seam inject the entity manager normally into the EntityQuery?

              • 4. Re: different EntityManagerProxy at every request
                jbossindia

                u mean what through @Create validate method of EntityQuery


                but that's not getting called when I use EntityQuery as composition inSFSB.

                • 5. Re: different EntityManagerProxy at every request
                  jbossindia

                  Also I require EntityManager in my SFSB beans across conversations for CRUD operations.


                  My objective is to have SFSB for listing(query) and CRUD operations together in conversation.


                  While i tried using sem-gen created home and query objects even then EntityManager is closed exception was coming in clustered environment.


                  FYI i am working in clustered environment.

                  • 6. Re: different EntityManagerProxy at every request
                    pmuir

                    Kulvinder Singh wrote on Mar 12, 2008 11:41 AM:


                    While i tried using sem-gen created home and query objects even then EntityManager is closed exception was coming in clustered environment.

                    FYI i am working in clustered environment.


                    Here is the critical piece of information ;-) See JBSEAM-2666.

                    • 7. Re: different EntityManagerProxy at every request
                      jbossindia

                      hi pete, I also debugged to the same point as mentioned in JIRA issue.


                      when will this get fixed as in the issue a patch is provided by removing the code calling entityManager.close()


                      is this right approach?


                      shall we take it for the time being as it is?

                      • 8. Re: different EntityManagerProxy at every request
                        pmuir

                        Kulvinder Singh wrote on Mar 12, 2008 01:27 PM:


                        when will this get fixed as in the issue a patch is provided by removing the code calling entityManager.close()


                        As indicated in JIRA, this is scheduled for the 2.1.x timeframe - i.e. undefined. Vote for the issue to get it pushed up.


                        is this right approach?



                        Don't know - if I did, it would make fixing the issue easy :-p

                        • 9. Re: different EntityManagerProxy at every request
                          cpopetz

                          Kulvinder Singh wrote on Mar 12, 2008 01:27 PM:


                          is this right approach?



                          I can't say it's the right approach, but as the author of the patch, I can verify that we've been running in production on a cluster with 18 nodes for a few months, with no glitches.  And it also survived programmatic load testing.


                          Of course, our usage patterns may not be yours, so YMMV.


                          -Clint

                          • 10. Re: different EntityManagerProxy at every request
                            jbossindia

                            Thanks Clint and Pete


                            for the time being I can live up with without cluster but 1 month later I would need the same.


                            How to make this issue in priorty as it is critical in general.