0 Replies Latest reply on Aug 27, 2012 1:03 AM by vinay0986

    when updating the cureent object,the previously selected object is going to be updated in jboss seam

    vinay0986

      I am using jboss seam, In my code i am using @StateFul session,Session scope and extended persistence context. when i am going to update the current object using entity-manager.merge(obj) and entity-manager.flush() ,the current is updated successfully. my problem is when i select one object(ex obj1) for update and give some fields to that object ,the provided data is failed based on my logical conditions ,so its not updated ..and i omit that object and select and another object(ex obj2) and provide some correct information to that object(obj2),when i am going to update that current object (obj2) the previously selected objects(like obj1) which is not updated,all those objects is updated with current object(obj2)......... plz slove my problem,

       

       

         @Stateful
      @Name("CustomerAction")
      @Scope(ScopeType.SESSION)
      public class CustomerAction implements
         
      CustomerInterface {

      @PersistenceContext(type = PersistenceContextType.EXTENDED)
      private EntityManager  entityManager;
         
      private String name;
         
      Customer selectobj;---->entity
      public void objectSelected() {
         
      ((org.hibernate.Session) entityManager.getDelegate())
         
      .setFlushMode(org.hibernate.FlushMode.MANUAL);
          selectobj
      = (Customer) entityManager.createQuery(
                 
      "from Customer where custName=:id").setParameter("id",name)
                 
      .getSingleResult();
          entityManager
      .refresh(selectobj);
      }
      @Transactional<br>
      public void update() {
      if (selectobj.age<18) {
              facesMessages
                     
      .addToControl("messages", Severity.ERROR,
                             
      "Age should be greather than 18");
             
      return;
         
      }

              selectobj
      .setModifiedBy(user.getUserId());
              selectobj
      .setModifiedDate(currentDate.getCurrentDate());
              entityManager
      .merge(selectobj);
              entityManager
      .flush();
              entityManager
      .refresh(selectobj);

      }
      @Destroy
      @Remove
      public void destroy() {
      }  
      }