6 Replies Latest reply on Feb 14, 2013 6:29 PM by Tony Herstell

    Catch 22 with JBAS011437

    Tony Herstell Master

      I get this error:

       

      JBAS011437: Found extended persistence context in SFSB invocation call stack but that cannot be used because the transaction already has a transactional context associated with it.  This can be avoided by changing application code, either eliminate the extended persistence context or the transactional context.  See JPA spec 2.0 section 7.6.3.1.  Scoped persistence unit name=xxxx.war#xxxDatasource, persistence context already in transaction =org.hibernate.ejb.EntityManagerImpl@1218f921, extended persistence context =ExtendedEntityManager [xxx.war#apiarymanagerDatasource].

       

      I have a conversational bean

       

      // Leverage EJB to get Transactional Support
      @Stateful
      // Lets be long running (multiple client-server round trips) - Needs Extended on
      // PersistanceContext too to hold onto my objects and not get LIEs.
      @ConversationScoped
      // EL Can can find me...
      @Named
      public class OrganisationManagementController extends BaseController {
      
          ...
      
          // Access to the persistence store so we can read from the DB with Long
          // Running extension to go with Conversation Scope above.
          @PersistenceContext(type = PersistenceContextType.EXTENDED)
          private EntityManager em;
      
          ...
      

       

      I have to used PersistenceContextType.EXTENDED to stop getting LIEs (Lazy...).

       

      In the rountine (inside the running conversation):

       

      public String createOrganisation(Organisation organisation) {
              this.logger.info(">>>createOrganisation");
      

       

      I need to grab something so do a query to get it...

       

       List<OrganisationRole> listWithAdministratorRoleForAdmin = this.em.createQuery("select role from organisationRole role where role.organisationRoleKind = :role").setParameter("role", OrganisationRoleKind.ADMINISTRATOR)
                          .getResultList();
      

       

      This gives the exception....

       

      Since:

      1. I cannot stop using PersistenceContextType.EXTENDED as its Conversational (see above)

      2. Its Transactional @Stateful

      please can you suggest a solution.

       

      This is also very odd as I didn't get it yesterday at COP (the only changes yesterday were to rip out all JEE Events logic as found it was the root cause of some very strange errors).

        • 1. Re: Catch 22 with JBAS011437
          Tony Herstell Master

          Should the txn be null?

          em.jpg

          • 2. Re: Catch 22 with JBAS011437
            Tony Herstell Master

            Ok,

            Found the culprit but dont know WHY????

             

            I am injecting a class:

             

             

                @Inject
                OrganisationInUseController organisationInUseController;
            

             

            This was Stateful.

             

            by making it not Statful the problem went away.

             

            Now to see what side effects that has...

             

            :/

            • 3. Re: Catch 22 with JBAS011437
              Tony Herstell Master

              The side effects was lots of LIEs in that class as it needed to be stateful too.

              So back to catch22

              • 4. Re: Catch 22 with JBAS011437
                Tony Herstell Master

                By making it back to be stateful; and adding @RequestScoped all the problems go away

                 

                @Stateful // <- adding this causes a problem in OrganisationManagementController when running a Query [JBAS011437: Found extended persistence context in SFSB invocation...]
                @RequestScoped // <<--- added for random reason (reduce scope down; to make it more Spring like to see if it makes the problem go away as it does in a lot of cases)
                

                 

                All I got figure out is why I guesss...

                • 5. Re: Catch 22 with JBAS011437
                  henry katz Newbie

                  I encountered the same issue as you had. I am building a seam3/weld app based on the jboss-javaee6-webapp archetype.

                   

                  The solution I used was stolen from another demo app on confbuzz: https://github.com/seam/seam-example-confbuzz.git

                   

                  which produces the following entity manager in the resources bean:

                   

                  @Produces
                  @ExtensionManaged
                  @ConversationScoped
                  @PersistenceUnit
                  private EntityManagerFactory primary;

                   

                  instead of

                   

                  /* @SuppressWarnings("unused")
                  * @Produces
                  * @PersistenceContext private EntityManager em;
                  */

                   

                  So in my @stateful @ConversationScoped bean where I do all CRUD, I made the following slight change:

                   

                  @Inject //PersistenceContext(type = PersistenceContextType.EXTENDED)
                  private EntityManager em;

                   

                  which seems to work.

                   

                  This may not match all your maven dependencies as I had to add SEAM3 artifacts in order to handle the weld 321 view expired exception which SEAM solder does nicely.

                   

                  I needed conversation scope in my SFSB as I try to minimize database access once the collection is read from it.

                   

                  hth,

                  Henry

                  • 6. Re: Catch 22 with JBAS011437
                    Tony Herstell Master

                    I am glad you found a workround.

                     

                    I am not convinced that Conversation scope it being supported very well even though people, in the trenches, are using it daily...

                    I get the feeling that yet more mashup, RESTful, gimmicks are driving the future and these are all Stateless/"everything on the page" projects as they are more visible.

                     

                    JSF 2.2. is introducing FacesFlow (https://blogs.oracle.com/arungupta/entry/jsf_2_2_faces_flow).

                     

                     

                    Without Conversation Scope:

                    "Implementing such flows has in the past been done with ad-hoc techniques, like simply linking full pages to each other and using the session scope to pass information between pages. The problem here is that this makes the result difficult to re-use and not safe when the user opens the same flow in more than one window."


                           http://jdevelopment.nl/jsf-22/

                     

                    I can ONLY hope that they have considered transaction boundaries as one of the beauties of conversation scope is the ability to make changes to the DB over a number of pages and have them all rolled back as you cancel the Conversation.

                     

                    FacesFlow could be great, but it still does not address the problem that was solved with Business Scope (jBPM) in Seam 2; and next time I need this (comign up) I am hoping Drools will save me as I doubt JEE 7 will.

                     

                    :/