3 Replies Latest reply on Jun 8, 2007 8:13 AM by pmuir

    Persistence Question

      Hi, I have this situation:

      I have a Seam generated application (so I use lots of the generated code)

      I enter on the edit screen of entity B from the list.
      B has a combo box of entity A. Near this combo box there is a link that sends me to the edit screen of the instance of A (A1) that is referred in the instance of B (B1).
      I placed an attribute on entity A (transient) and on the edit screen, a combo box that allows me to create a new instance of A.
      So, the flow would be this:
      If I check the checkbox, I must "clone" A1 into A2, insert A2 into the DB, update B1.setA( A2 ), then update it into the DB.
      If i don't check the box, then update A1.

      I do this in the AHome class, in the update method:

      public String update()
      {
       A a= getInstance();
       B b = bHome.getInstance();
       if( a.isSaveAsNew() )
       {
       A newA = a.duplicate();
       B.setA(newA);
      (1)
       return persist();
       }
       else
       return super.update();
      }


      But, the problem is that A1 also gets updated, and I don't want this to happen. I read on the forum something about FlushType.MANUAL. But I don't start a conversation, so what else can I do?

      I tried different methods, even to set the newA as the instance, but always a gets updated.

      Anyone, any idea?

        • 1. Re: Persistence Question
          pmuir

          You've updated A1, a persistent entity, so when you flush the Persistence Context, i the changes get persisted. If this was just regular java objects, you wouldn't expect the above to work... so, redesign so it would work with plain java objects and then add in your pesistence - *don't* use the PC to play tricks!

          • 2. Re: Persistence Question

            I know they are persisted.

            But I don't have much experience with EJB3, JPA, Hibernate...

            I hoped that maybe there is some way to say "ignore the update on this entity" to the persistence manager.

            • 3. Re: Persistence Question
              pmuir

              Thats what I mean by tricks ;)