-->
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.  [ 3 posts ] 
Author Message
 Post subject: Getting exception could not resolve property
PostPosted: Fri May 04, 2007 3:46 am 
Newbie

Joined: Sat Apr 21, 2007 9:48 pm
Posts: 9
Hello All,
It looks very simple problem but I am not able to figure it out :(

If I execute List crit = session.createCriteria(LottoResult.class).add (Restrictions.eq("lotto.price", new Integer(11))).list(); ; it gives me following exception :
org.hibernate.QueryException: could not resolve property: lotto.price of: com.lottos.domain.LottoResult
at org.hibernate.persister.entity.AbstractPropertyMapping.propertyException(AbstractPropertyMapping.java:44)

mapping and source code is below:
<hibernate-mapping>
<class name="com.lottos.domain.Lotto" table="lotto">
<id name="id">
<generator class="native"/>
</id>
<property name="price" not-null="true"/>
</class>
</hibernate-mapping>

<hibernate-mapping>
<class name="com.lottos.domain.LottoResult" table="lottoResult">
<id name="id">
<generator class="native"/>
</id>
<many-to-one name="lotto" class="com.lottos.domain.Lotto"
column="lottoId" not-null="true"
fetch="select" lazy="false"/>
</class>
</hibernate-mapping>


public class Lotto {
int id;
int price;
public int getPrice() {
return price;
}

private void setPrice(int price) {
this.price = price;
}

int price;
.....
}


public class LottoResult {
Lotto lotto;
public Lotto getLotto() {
return lotto;
}

public void setLotto(Lotto lotto) {
this.lotto = lotto;
}
}

Help is highly appreciated.


Top
 Profile  
 
 Post subject: Use an Alias
PostPosted: Fri May 04, 2007 8:27 am 
Beginner
Beginner

Joined: Thu Nov 11, 2004 12:18 pm
Posts: 37
Location: Baltimore, MD
Try this:

Code:
   
getSession().createCriteria(LottoResult.class)
   .createAlias("lotto", "lotto")
   .add(Restrictions.eq("lotto.price", new Integer(11)))
   .list()


Creating the alias on "lotto" will set up the join between the tables (which seems like what you need here). The default type of join is INNER JOIN, but you can add an optional 3rd parameter to createAlias to specify a Full or Left Outer join as well.

_________________
-Chris


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 04, 2007 11:18 am 
Newbie

Joined: Sat Apr 21, 2007 9:48 pm
Posts: 9
Thanks a lot it worked. Still i am not sure why I have to explicitly create Alias; in the mapping file I have already specified foreign key relationships..

Anyway thanks for ur help.. it works and thats what matters :)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.