1 Reply Latest reply on Mar 9, 2010 12:23 AM by Arbi Sookazian

    Can I use Seam conversation scope PC in Jetty?

    philip andrew Newbie


      Previously I was using JBoss, now I am using Jetty (have to, client requirement).

      I am using Jetty, what I want to do is select an entity into the conversation scoped persistence context (but I am not sure if I have one). But what I find is that when I update() without a merge, no change is committed to database. In the update, if I persist() without a merge first then it says my entity is detached. I have:

      public class NewsHome extends HibernateEntityHome<ONews> {
        private static final long serialVersionUID = 1L;
        private Session hibernateSession;

        @Begin(join = true)
        public void select() {
          if (this.getId() != null)
            ONews news = find();

      ... ok so here are some questions.

      1. Can I have conversation scoped persistence context with attached entities in jetty? My pattern would be to select() the entity when user clicks edit button, then to update() when the user presses save.

      2. Why in my case do I must do a merge? ... it must be the case that although I have a conversation, I dont have a conversation scoped persistence context.

      3. How can I get a conversation scoped persistence context in Jetty?

      Thanks, Philip

        • 1. Re: Can I use Seam conversation scope PC in Jetty?
          Arbi Sookazian Master

          AFAIK, the SMPC, conversation scope, and Hibernate manual flush are all independent of the RDBMS and app server you're using.  That being said, I've only worked on Seam projects with SQL server and Oracle RDBMS's.

          Also, I've used the following exclusively for SMPC injection:

          @In EntityManager entityManager;

          and this for Hibernate Manual flush:

          @Begin(join=true, flushMode=FlushModeType.MANUAL)

          to flush the PC changes to the DB:


          But in your case you're using Hibernate Session injection.  So this is from the ref doc:

          To configure Hibernate managed transactions declare the following in your components.xml where
          #{hibernateSession} is the name of the project's persistence:managed-hibernate-session
          component. If your managed hibernate session is named session, you can opt to leave out the
          session attribute. (see Seam-managed persistence contexts )
          <transaction:hibernate-transaction session="#{hibernateSession}"/>

          more from ref doc:

          In either case, you'll need to use a managed persistence context (for JPA) or a managed session
          (for Hibernate) in your components. A Seam-managed persistence context is just a built-in Seam
          component that manages an instance of EntityManager or Session in the conversation context.
          You can inject it with @In.

          AFAIK, you do not need to use the merge() operation, if you are using the default AUTO flushMode, when the transaction commits at the end of the method marked @Transactional, the changes in the PC should be persisted to the DB.

          see 9.3.2. Using a Seam-managed Hibernate session in the ref doc:

          Note that Seam does not flush the session, so you should always enable
          hibernate.transaction.flush_before_completion to ensure that the session is automatically
          flushed before the JTA transaction commits.