5 Replies Latest reply on Jan 30, 2012 12:53 PM by Bernard Labno

    SMPC alternative

    Bernard Labno Master

      I'm using Seam managed persistence context scoped to conversation. But now I want to access it from resteasy.
      I'm getting


      WELD-001303 No active contexts for scope type javax.enterprise.context.ConversationScoped



      1. How can I configure separate persistence context?


      2. How to turn conversation scope on for rest calls?

        • 1. Re: SMPC alternative
          Bernard Labno Master

          I attach my temporary solution for additional non-managed persistence context. Note that @Regular is a custom Qualifier.


          The problem is that if I don't want to use that persistence context directly but use some DAO that needs PersistenceContext injected then this won't work cause DAO wants SMPC.


          Is it possible to annotate injection point so that SMPC is used if available and @Regular otherwise?




          public class EntityManagerProducer {
          // ------------------------------ FIELDS ------------------------------
          
              private final String PERSISTENCE_UNIT_NAME = "some-unit";
          
              @ExtensionManaged
              @ConversationScoped
              @Produces
              @PersistenceUnit(unitName = PERSISTENCE_UNIT_NAME)
              private EntityManagerFactory emf;
          
          // -------------------------- OTHER METHODS --------------------------
          
              @Regular
              @Produces
              public EntityManager getEM(@Regular EntityManagerFactory entityManagerFactory)
              {
                  return entityManagerFactory.createEntityManager();
              }
          
              @Regular
              @Produces
              public EntityManagerFactory getEmf()
              {
                  return Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME);
              }
          }

          • 2. Re: SMPC alternative
            Jason Porter Master

            Scoping it to a different scope didn't work for you?

            • 3. Re: SMPC alternative
              Bernard Labno Master

              Jason, I'd like to have one default (mostly used from JSF) persistence context scoped to conversation.
              But I also want to produce RSS feed with resteasy and abdera. Conversation is not available from rest call and i'd like to use my DAO's instead of that @Regular EntityManager.


              So, changing scope is not an option here.

              • 4. Re: SMPC alternative
                Jason Porter Master

                Hm. Are you using the Seam Conversation module? IIRC, Seam Rest can use it to enable the conversation scope for Rest. I haven't looked at it myself, but that may be one route to take.

                • 5. Re: SMPC alternative
                  Bernard Labno Master

                  Thanks Jason for pointing me into right direction.


                  I've mapped ConversationFilter to rest stuff.


                  Now I can user ConversationScoped beans in Rest beans! Jupi!