Hibernate version: 2.1.8
I am having the following problem:
I have a class hierarchy mapped to one table like so:
AbstractClass discriminator-value="null"
|-> ConcreteClass1 discriminator-value="C1"
|-> ConcreteClass2 discriminator-value="C2"
|-> ConcreteClass3 discriminator-value="C3"
My discriminator column is defined as such:
Code:
<discriminator
column="obj_type"
not-null="true"
type="string"
length="2"/>
I try the following:
Code:
// load an object, it is actually an instace of ConcreteClass3
Object o = session.load(AbstractClass.class, 3);
// ....
// change a couple of properties
// ...
session.saveOrUpdate(o);
Then in a different session:
Code:
Object o = session.load(AbstractClass.class, 3);
This second time a WrongClassException is thrown along the lines:
Object with id: 3 was not of the specified subclass:
ConcreteClass1 (loaded object was of wrong class)
Notice, how it thinks I have specified the loaded class as
ConcreteClass1.
After a lot of trial and error I tried switching off ehcache; and surprisingly enough it works flawlessly. Also, if I have the cache enabled, and I let some time pass between saving and reloading it works fine presumably because the relevant cache entry has expired.
Has anyone else encountered this weird behavior? I haven't found the solution myself after a lot of searching and I would appreciate any tips.
Many thanks,
Giorgos