I'm using basic table-per-class polymorphism in Hibernate. So I have:
<class name="SuperClass" table="SUPER">
<id name="anId" type="long">
<generator class="native"/>
</id>
<properties name="uniqueFields" unique="true">
<property name="one" not-null="true"/>
<property name="two" not-null="true"/>
</properties>
<joined-subclass name="SubClass1" table="SUB1">
<key column="anId"/>
<property name="other"/>
</joined-subclass>
<joined-subclass name="SubClass2" table="SUB2">
...
</joined-subclass>
...
</class>
So, basically I have a bunch of subclasses, each of which is holding some subclass specific data. I have a key, but I also need a compound unique constraint on a couple of other properties.
If a create a criteria:
createCriteria(SubClass1.class).add(Restrictions.eq("one", "VALUE")).list()
I get a stack dump caused by: Invalid column name 'one'.
If I create the criteria based on SuperClass.class it works, but a need to add restrictions that apply to both the superclass and the subclass (and this code is actually buried under a whole lot of other stuff).
I can get to the key, but it is declared in both places. Can I not access the global properties from the subclass in a criteria? Do I need to declare them somehow? Or some type of cast?