2 Replies Latest reply on Feb 21, 2006 7:44 AM by Emmanuel Bernard

    flush in  EXTENDET Persisten context

    Peter Repinc Newbie


      I have a problem. I want to write an application using long running transactions.
      My usecase is with several steps:
      1. I want to create and persist an object
      2. This object is subsequently changed
      3. At the end I want to save (flush) changes to the database.
      To achieve this behavior I tried to use PersistentContext in EXTENDED mode. I have written stateful session bean which implements all steps. This did not work so I have tried how TraiBlazer application is working

      In the module Runtime services ? Application transactions ? there is an example of stateful session bean running with a persistent context in the extended mode.

      @Stateful
      public class ApptransCalculator implements Calculator, Serializable {

      @PersistenceContext(
      type=PersistenceContextType.EXTENDED
      )
      protected EntityManager em;

      // ... ...

      }

      In the example the flush and commit to the database should happen only when the checkout method is called. In example the checkout method is called in the update2.jsp (check.jsp). I have repacked the EJB3Trail.ear with some changes:
      1. I enabled show_sql property for Hibernate.
      2. I have changed the datasource to oracle.

      I monitored the changes in the database after each step. I found out that it behaves not as the example is trying to show. The click on update button on update.jsp (calculator.jsp) writes to the database. Now the question is: Am I understanding something wrong or is these just not working as it should? As I understand flush should happen when checkout method (which is annotated with @Remove) is called.

      Thanks
      Peter Repinc