Hi!
I have JBoss with Hibernate 3.2.0.cr2
Mapping :
Code:
<class name="Thing">
...
<!-- bi-directional many-to-one association to ThingGroup -->
<many-to-one name="thingGroup"
class="ThingGroup" not-null="true">
<column name="THING_GROUP__KEY" not-null="true" />
</many-to-one>
...
</class>
Class definition :
Code:
public class Thing {
...
private ThingGroup thingGroup;
...
}
ThingGroup has three subclasses. TG1, TG2 and TG3.
It is mapped as table per class hierarchy (with a discriminator)
The question is, how do I query for Thing objects, that are associated to TG1 objects , not TG2 , TG3 or ThingGroup ?
Currently we use this code :
Code:
Criteria critT;
Criteria critTG;
// Thing
critT = getSession().createCriteria(Thing.class);
// Thing Group
critTG = critT.createCriteria("thingGroup");
critT.add(isNull("someProperty"));
critT.add(eq("someOtherProperty", someValue);
// try to limit to TG1 type
critTG.add(eq("discriminator", "TG1"));
The last line of course does not work, as the discriminator is not mapped to any java field.
Is there a Criterion, that would mean something like isAssignableTo(TG1.class) ?
Thanks !
David