I have several servers using Hibernate 3.3 for reading/writing objects of class 'C'. Every once in a while I modify the DB schema (i.e. add new fields), and update class 'C' accordingly.
As I was planning to add an L2 cache (memcached) for performance reasons, I stumbled across the following problem:
The upgrade process takes an hour or so, during which the servers are upgraded one after the other.
If a server that was already upgraded tries to fetch an object from the cache, and this object was not yet modified in the Cache to include the new fields, Hibernate generates an 'ArrayOutOfBounds' Exception upon trying to de-serialize the old shorter object using the new longer definition.
Is there an elegant way avoid this exception, e.g. override the serialization process?
Is there a better way to tackle this issue altogether?
Please note that this problem has nothing to do with with the actual cache mechanism. The 'problematic' code is in Hibernate: TypeFactory.assemble().
subject: handling multiple class versions in Hibernate L2 cache