-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: org.hibernate.HibernateException: Unable to resolve property
PostPosted: Fri Apr 16, 2010 11:37 am 
Newbie

Joined: Fri Apr 16, 2010 11:29 am
Posts: 5
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.


Top
 Profile  
 
 Post subject: Re: org.hibernate.HibernateException: Unable to resolve property
PostPosted: Thu Aug 05, 2010 7:21 am 
Newbie

Joined: Fri Apr 16, 2010 11:29 am
Posts: 5
Just in case anyone else stumbles across this...

Because my foreign keys were primary keys, I had to create a <property> tag for each in order for it resolve. Sounds logical when one looks at the error, but only once one realises that an <id> is not a property.

I changed my second entity's HBM as follows:
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>
<!-- new -->
        <property name="alertTriggerId" type="int" insert="false" update="false">
            <column name="alert_trigger_id" not-null="true" />
        </property>
<!-- /new -->
        <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>


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.