0 Replies Latest reply on Aug 31, 2009 11:46 AM by Vasilii Lukoyanov

    BMT, entity persists into DB before tx commit

    Vasilii Lukoyanov Newbie

      Hi.


      In my application I want to perform several JSF action invocation inside one transaction. Therefore I decided to use BMT, but I run into problem that when entity is persisted it immediately (well, actually after action finished) flushed into DB (checked with pgadmin).


      Please, tell me where I'm wrong.
      Here is the STSB:



      @Stateful
      @Name("addCPAction")
      @TransactionManagement(TransactionManagementType.BEAN)
      @Scope(ScopeType.CONVERSATION)
      public class AddCoursePlanAction  implements AddCoursePlan {
      
          @Logger
          private Log _log;
      
          @PersistenceContext(type = PersistenceContextType.EXTENDED)
          private EntityManager _em;
      
          /** Транзакция */
          @Resource
          private UserTransaction _tx;
      
          @In(value = "coursePlanHome", scope = ScopeType.CONVERSATION, required = false)
          private CoursePlanHome _plan;
      
          @In(value = "courseUnitHome", required = false)
          private CourseUnitHome _unit;
      
          public void requreTx() {
              try {
                  if (_tx.getStatus() == Status.STATUS_NO_TRANSACTION) {
                      _tx.begin();
                  }
              } catch (Exception e) {
                  _log.debug(e.getMessage(), e);
              }
          }
      
          public String addPlan() {
              return "success";
          }
      
          @End(beforeRedirect = true)
          @Transactional(TransactionPropagationType.NEVER)
          public String addUnit() {
      
              if (_unit == null) {
                  _log.debug("Категория пустая, не добавлено");
                  return "failure";
              }
      
              if (_plan.getInstance().getItems() == null) {
                  _plan.getInstance().setItems(new HashSet<CourseUnit>());
              }
      
              _plan.getInstance().getItems().add(_unit.getInstance());
      
              requreTx();
              _em.persist(_unit.getInstance());
      
              return "success";
          }



      addUnit() action is called during nested conversation. Conversation is started from EntityHome.create().



      Thanks in advance, sorry for english.