Hi,
I've got a situation where I have set up appropriate cascading on associations to create them without having to worry about saving those objects directly, essentially allowing hibernate to do its stuff. This works well and I'm happy with that when my business code is in charge of the creation. However, on receiving a dettached domain object from another application, I only want to update the top level entity itself, only its base properties not any underlying associations, to limit any stupidity from the client. The update essentially pertains only to the inbound entity.
Currently, in the update method on my service I just do a lookup of the object from the db and copy the properties from the inbound object in to the looked up version and then allow the changes to flush. This means I am in control of which props get updated:
Code:
public void update(Object obj) {
Object toUdate = dao.get(obj.getId());
//call the copy method to update only those props that are valid
toUpdate.copy(obj);
//implicitly save on transaction completion
}
However as I am not reattaching the object to the session, this removes the ability to use Hibernate's automatic versioning and optimistic locking that could be achieved with reattaching.
Question is; is there any way to change the cascading settings based on the reattachement to only flush changes to the top level object? i.e. I am happy with my cascade settings when creating objects during a session and when I am in control, but don't want those cascades to apply on reattaching the object to a session.
Apologies on the long post, can't cut it down much smaller :)
Thanks