Thursday, January 27, 2011

EOs with transient Attributes - will they be locked if no other change?

Found this post on an internal forum and thought of putting it down here :-

Problem :
We have some EOs with some attributes not mapped to any DB Table Column whereas some other attributes are mapped to DB Table columns. During runtime, sometimes we set only these "transient" attributes in the underlying EO and not the Column-mapped Attributes.
The question is, if we call am.commit(), will ADF Framework try to lock()/commit() these EOs with only changes in transient attributes?

Solution:
1.Modifying an attribute marks the entity as changed whether it's transient or not. To avoid this, you can use populateAttribute instead of setAttribute to set the transient attributes. If they are set from the UI, you can override setAttribute to call populateAttribute. The overview for EntityImpl javadoc here has a good explanation of set and populate methods. Same methods available in the view row.

2.Run time would mark the specific EO instance as dirty (STATUS_MODIFIED), and will take the EO through normal Txn cycle. However only those modified persistable attributes are posted back to DB