0

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?

Paul W Homer
  • 2,728
  • 1
  • 19
  • 25
  • what happens if you remove ``? – Firo Aug 14 '12 at 08:39
  • Not sure, but that constraint is very important. Normally if I create a criteria on the subclass, should I be able to access elements of the super ? – Paul W Homer Aug 14 '12 at 18:26
  • AFAIK yes, it should be possible, however i am only certain for NHibernate but it is very close to Hibernate – Firo Aug 14 '12 at 19:38

0 Answers0