aabeling wrote:
How about adding logic to your update() method which checks whether the IS_DELETED or IS_AGENT values changed. If yes the method can throw an exception or ignore the changes and just update the rest.
No, this is bad on so many levels.
First at all, at the moment of update() we have only client-modified version. To make a comparision we need to load current one, which is another SQL query.
Second, having setter for a "secure" property misleads client, who can believe it's alright to change this property directly.
So after some brainwashing ;) I decided to remove those properties from the mapping completely; instead, I introduced a small control mapping for the same table, which contains primary key and "secure" properties. This way client never see those properties as a part of the object, but can manipulate them through DAO-exposed methods. Control beans aren't visible to client, it's a detail of implementation.
mapping:
Code:
<class name="com.cibc.gdp.cbb.bean.User" table="USER">
<id name="key" column="USER_KEY">
<generator class="com.cibc.gdp.cbb.dao.hibernate.DaoLegacyStrategyPrimaryKeyGenerator"/>
</id>
...
</class>
<class name="com.cibc.gdp.cbb.dao.bean.UserCtrl" table="USER">
<id name="key" column="USER_KEY"/>
<property name="deleted" column="DELETED_FL" type="com.cibc.gdp.cbb.dao.hibernate.usertypes.YesNoBoolean"/>
<property name="isAgent" column="IS_AGENT" type="com.cibc.gdp.cbb.dao.hibernate.usertypes.OneZeroBoolean"/>
</class>
code (under SpringFramework):
Code:
public void delete(User user) {
UserCtrl ctrl = new UserCtrl();
ctrl.setCtrlKey(user.getUserKey());
ctrl.setDeleted(true);
getHibernateTemplate().merge(ctrl);
}
it works fine for me.