BC4J Helper by Sung Im
Thoughts on how BC4J works, code samples, and other helpful techniques
        

Difference between Entity State and Post State of Entity Row

EntityImpl has two methods:

   public byte getEntityState()
   public byte getPostState()

The first one returns the entity-state (aka transaction state or effective state), while the second one returns the post-state.

The difference between post-state and entity-state is this.  Post state
tells the state of the entity object wrt the last post.  Entity state is
the state wrt the whole transaction.  Keep in mind an EO may be written
to db (post) many times in one transaction before it is committed.

So, after a post, the post-state may go to UNMODIFIED but entity-state
may remain MODIFIED.  Here is an example.  Suppose you're reading a row
in:

   row = vo.first();  // read an EO in from DB.  Both states
                      // are UNMODIFIED

   row.setAttribute("SomeAttr", someValue);
                      // After this, both states are MODIFIED.

   am.getTransaction().postChanges();
                      // Changes are written to DB.
                      // Trans not committed yet.
                      // After this, post-state is UNMODIFIED.
                      // Entity-state is MODIFIED.

   am.getTransaction().commit();
                      // Transaction committed.
                      // After this, both states are UNMODIFIED.

 



© Copyright 2004 Sung Im. Click here to send an email to the editor of this weblog.
Last update: 5/25/04; 10:38:49 AM.