I have a class A and 3 subclasses of A (B, C and D) persistent in the same table. Only the classes C and D implements a Interface Intf.
At a certain point in my application I get a primary key of a entity which is a Implementation of Intf (dont know if is it a entity of type C or D). So I try to use as first lookup Session.get(C.class, thePrimKey) and as second lookup Session.get(D.class, thePrimKey) if the first lookup return null. But unfortunately it seems get() try to fetch the data of the database row in a instance of type C ignoring the ignoring the discriminator value of the row. I get a PropertyAccessException when Hibernate try to fill a property on type C which not exists on type D. When I try first a lookup with Session.get(D.class, thePrimKey) and it's a primary key of a C type entity I receive a WrongClassException (?). Why it's a different exception now?
I expected that get() return null if there is no entity for the given key and type?
I there a fix or workaround for it? How can I find the requested entity of type C or D which implements Intf ?
Thank you very much
|