Marking an Entity Object as modified

There are use cases where developers may need to explicitly set the Entity Object state as modified so that it becomes 'dirty' and participate in the 'transaction commit' cycle. This scenario usually arise where you may have Entity Objects(not exposed through UI) whose attributes needs to be populated by the system as 'history columns' or through database trigger, when a transaction gets committed. Please note that only dirty entity instances participate in transaction post cycle. How to mark an entity instance as modified? Unfortunately, there is no public API available at EntityImpllevel to mark the instance as as modified (EntityImpl::setState() is a private method). A work around solution for this specific scenario is to brutally set one attribute of the EntityImpl instance with its current/original value.

//purely a work around,
//currentValue is same as someEntityImpl.getSomeAttribute()
someEntityImpl.setSomeAttribute(currentValue);

This action would mark the instance as dirty('STATUS_MODIFIED'), and it becomes a candidate for transaction post cycle.

Comments

  1. Where to set this in the EOImpl?
    Should it be placed inside the EO create method?

    ReplyDelete
  2. Where to set this in the EOImpl?
    Should it be placed inside the EO create method?

    ReplyDelete

Post a Comment