Hibernate caches raw arrays of field values in L2 cache. If that cache is clustered, and you want to update nodes one by one, you can get into a lot of trouble. Session may fetch a cache entry with old schema and blindly try and copy it to an entity. Sometimes it leads to ClassCastException. It also may lead to data corruption (disassembling a field as null and then saving that to database).
There does not seem to be a way to work this around. serialVersionUID is unsupported and I don't see a way to mark entity definition version anywhere in the mapping.
I'm experiencing this in 3.3.1, but from a brief source code inspection it seems to still be an issue in 4.
I sparked some discussion on my blog (with ideas for fixes): http://squirrel.pl/blog/2011/08/24/hibernate-cache-is-fundametanlly-broken
And on Reddit: http://www.reddit.com/r/java/comments/jtbsy/hibernate_cache_is_fundamentally_broken/
(Just to avoid reiterating the same arguments)
In an effort to clean up, in bulk, tickets that are most likely out of date, we're transitioning all ORM 3 tickets to an "Awaiting Test Case" state. Please see http://in.relation.to/Bloggers/HibernateORMJIRAPoliciesAndCleanUpTactics for more information.
If this is still a legitimate bug in ORM 4, please provide either a test case that reproduces it or enough detail (entities, mappings, snippets, etc.) to show that it still fails on 4. If nothing is received within 3 months or so, we'll be automatically closing them.
Thank you!
Bulk rejecting stale issues. If this is still a legitimate issue on ORM 4, feel free to comment and attach a test case. I'll address responses case-by-case. Thanks!