Hibernate version: 3.2.5.ga
Hibernate EntityManager version: 3.3.1.ga
Hibernate Annotations version: 3.3.0.ga
Name and version of the database you are using: Oracle 10g
Hi!
I'm using the following MergeEventListener to set my fields for userCre, timeCre, userUpd, timeUpd. The fields indicate when and from who the record was inserted or last updated.
Code:
public class DefaultMergeEventListener implements MergeEventListener {
private static final long serialVersionUID = 1L;
private final Logger log = new Logger(getClass());
public void onMerge(MergeEvent e) throws HibernateException {
if (e.getOriginal() instanceof Base) {
updateRecord((Base) e.getOriginal());
log.debug("update timestamp and userstamp for base record");
}
}
public void onMerge(MergeEvent e, Map arg1) throws HibernateException {
if (e.getOriginal() instanceof Base) {
updateRecord((Base) e.getOriginal());
log.debug("update timestamp and userstamp for base record");
}
}
public void updateRecord(Base record) {
// existing record
if (record.getId() != null) {
// TODO: updates appUser and time of every object in an object-tree
// causes to update all objects
record.setUserUpd(BasePlugin.getDefault().getAppUser());
record.setTimeUpd(new Date());
// new record
} else {
record.setUserUpd(null);
record.setTimeUpd(null);
if (record.getUserCre() == null)
record.setUserCre(BasePlugin.getDefault().getAppUser());
if (record.getTimeCre() == null)
record.setTimeCre(new Date());
}
}
}
My problem is the following: If I have a large object tree and I make a merge on the top object, all other objects of the tree gets updated. This can take a long time, because the object tree can have hundrets of objects.
So my question: How can I update my timestamps and userstamps properly? I would need something to set the stamps only on dirty objects.
Regards,
Chris.