Quote:
I set optimistic-lock="dirty", but I seem to have hit a road block in SessionImpl.flushEntity()
As per the Hibernate manual, optimistic-lock="dirty" is not intended for use with detached objects (mainly because I only added this feature to support existing features of JBoss CMP).
However, my todo list mentions: "optimistic locking which uses select-before-update (for "all", "dirty")"
I think the reason that is not working so far is that (as mentioned in the JavaDoc), getCurrentPersistentState() does not, and should not, return "resolved" state. It returns the "hydrated" state only: ie. associations are represented as just id values, whereas the ScheduledUpdate expects the fully resolved objects.
I'm not sure what a fix for this problem looks like.... I'm not certain, but it might be dangerous to resolve the hydrated state in the middle of flush (new objects will get loaded), and it could certainly be a performance problem.
Quote:
Is there any reason why the getCurrentPersistentState method does not check the second level cache before going to the database?
Same reason, the cached state is hydrated, which is not the format that getCurrentPersistentState() needs to return.
I agree it makes sense to use the cache. If you want to address
this limitation, you will probably just need to add an unresolve() method to the Type hierarchy.