I'm using Criteria-based querying to load a list of objects, based on a property of a linked object.
I have EventResponses (key: eventResponseId), which are triggered by an AlertTrigger (key: alertTriggerId), which in turn has a field userId. My query looks up event responses for a specific user.
The exception thrown is: org.hibernate.HibernateException: Unable to resolve property: alertTriggerId when calling list() on the Criteria query
My mapping docs are:
EventResponse
Code:
<hibernate-mapping>
<class name="org.rockitt.rrp.core.orm.EventResponse" table="event_responses">
<id name="eventResponseId" type="java.lang.Integer">
<column name="event_response_id" />
<generator class="identity" />
</id>
<property name="alertTriggerId" type="int">
<column name="alert_trigger_id" not-null="true" />
</property>
<property name="hash" type="string" unique="true" insert="false" update="false">
<column name="hash" not-null="true" />
</property>
<property name="status" type="string">
<column name="status" not-null="true" />
</property>
<many-to-one name="Event" class="org.rockitt.rrp.core.orm.Event" property-ref="hash" column="hash" unique="true"/>
<many-to-one name="AlertTrigger" class="org.rockitt.rrp.core.orm.AlertTrigger"
property-ref="alertTriggerId" column="alert_trigger_id" unique="true"
update="false" insert="false"/>
</class>
</hibernate-mapping>
And the mapping for my AlertTrigger entity:
Code:
<hibernate-mapping>
<class name="org.rockitt.rrp.core.orm.AlertTrigger" table="alert_triggers">
<id name="alertTriggerId" type="int">
<column name="alert_trigger_id" />
<generator class="identity" />
</id>
<property name="userId" type="int">
<column name="user_id" not-null="true" />
</property>
<property name="triggerTypeId" type="int">
<column name="trigger_type_id" not-null="true" />
</property>
<property name="active" type="boolean">
<column name="active" not-null="true" />
</property>
<many-to-one name="User" class="org.rockitt.rrp.core.orm.User"
property-ref="userId" column="user_id"
update="false" insert="false"/>
<many-to-one name="TriggerType" class="org.rockitt.rrp.core.orm.TriggerType"
property-ref="triggerTypeId" column="trigger_type_id"
update="false" insert="false" />
</class>
</hibernate-mapping>
My criteria code is:
Code:
Criteria crit = Hibernate.newCriteria(EventResponse.class, "er");
crit.createAlias( "AlertTrigger", "at");
crit.createAlias( "Event", "e");
crit.add(Restrictions.eq("at.userId", user.getUserId()));
crit.add( Restrictions.and(
Restrictions.ge("e.time", dateFrom),
Restrictions.le("e.time", dateTo)
));
I can't see where I'm going wrong - if I change the property-ref for the EventResponse#AlertTrigger relationship to, say, the triggerTypeId property of the AlertTrigger class, the list() proceeds without issue, so the problem is confined to the specific alertResponseId column, and I can't work out what's "special" about that column.
The EventResponse#Event object loads fine, the problem is confined to the AlertTrigger relationship.
Hopefully someone can help me out!
Thanks in advance.