hi all,
i've got a few classes here; Category is the parent.
Code:
Category
> Content Type ( child of Category )
> NavigationCategory ( child of Category )
** Note that these currently are NOT mapped as subclasses in Hibernate.
these are stored in the following tables:
Code:
iwsc_category ( Category )
iwsc_content_type (ContentType)
iwsc_navigation ( NavigationCategory)
the iwsc_category table has a discriminator column, category_type, which is there for extensibility. content type and navigation do not use this column (ie. it's not mapped in hb).
annnyway, here's the meaningful parts of the .hbm.xml:
Code:
<class name="Category" table="iwsc_category">
<id name="id" type="long" unsaved-value="-1">
<column name="category_id" not-null="true"/>
</id>
<many-to-one name="type" index="idx_iwsc_category_type_branch" column="type_id" foreign-key="fk1_iwsc_category_type_id" insert="false" update="false" class="CategoryType" not-null="true" />
...
</class>
<!-- this is NOT a HB subclass of Category -->
<class name="NavigationCategory" table="iwsc_navigation">
<id name="id" type="long" unsaved-value="-1">
<column name="category_id" not-null="true"/>
</id>
<property name="name" type="string" length="150" not-null="true"/>
...
</class>
... ContentType is similar to NavigationCategory...
When I run this:
Code:
Criteria hibernateCriteria =
session.createCriteria(Category.class);
.add(Restrictions.in("type",typeArray));
I get this error when I run the query:
Code:
Caused by: org.hibernate.QueryException: could not resolve property: type of:
com.foo.common.model.category.NavigationCategory
at org.hibernate.persister.entity.AbstractPropertyMapping.throwPropertyException(AbstractPropertyMapping.java:43)
at org.hibernate.persister.entity.AbstractPropertyMapping.toType(AbstractPropertyMapping.java:37)
at org.hibernate.persister.entity.BasicEntityPersister.toType(BasicEntityPersister.java:1094)
my question is, why is it even looking at NavigationCategory? While it is a subclass of Category in Java, it's not mapped that way in Hibernate. Not sure if this is a feature or a bug, but wondering if I (a) have to change my architecture to use type across the board or (b) there's a way to exclude the subclass in criteria-based queries.
i appreciate any help.
thanks and keep up the great work!
shanon.