hi hg,
just looking for some clarification on the implementaion of using ".class" in hql. After much searching i finally discovered that this notation requires the actual discriminator value in the query and not the class object that you want to search for. Since you don't have\need the discriminator value in java code why can't hibernate perform this mapping for us so that we don't even need to know about the discriminator?
Let me give you an example of how useful this would be, i have a dao method for finding all objects of a certain subclass which requires the class of object. here is what i would like to do:
Code:
public List listFixedCodes(Class fixedCodeType){
return getSession().find("from FixedCode as f where f.class = ?", fixedCodeType, Hibernate.CLASS);
}
Instead i either have to maintain a map of classes to discriminator values or do string manipulation using the class name, eg:
Code:
public List listFixedCodes(Class fixedCodeType){
return getSession().find("from FixedCode as f where f.class = ?", lookupDiscriminator(fixedCodeType), Hibernate.STRING);
}
or
Code:
public List listFixedCodes(Class fixedCodeType){
return getSession().find("from " + fixedCodeType.getName());
}
I thought that Hibernate wanted to hide implementation details from the user, a discriminator value has no use in java and as far as i am concerned should never be referenced outside of the mapping files.
Comments?
cam
Hibernate version: 2.1.5