damo9f wrote:
Hibernate version:
3.0.1
Mapping documents:
table-per-hierarchy mapping (three subclasses)
I (mistakenly) tried to load a class using another subclass's key, and got an instance back, of the wrong type.
E.g. I have classes X, Xa, Xb and Xc, where X is the superclass of the other three, I map them all to one table and perform
Xb xb = ...
Session s =...
Xa xa = s.get(Xa.getClass(), xb.getId());
and I get an Xa instance back holding xb's data. (The DB correctly stored the xb instance with the discriminator tag indicating it is an instance of Xb.)
If this is not a known issue, either bug it or let me know and I'll bug it.
Also using v3.0.1
Session.load(Class c, Object k) is behaving the same way.
In my case, Client and Partner both subclass Person and are declared with descrimiators and Person is defined with polymorphism="explicit"
Code:
Long clientId = new Long(1);
Object obj = null;
obj = session.get(Partner.class,clientId); // returns client data as a Partner object
obj = session.load(Partner.class,clientId); // returns client data as a Partner object
obj = session.createCriteria(Partner.class)
.add(Restrictions.eq("personId",clientId))
.uniqueResult(); // Correctly returns null.