-->
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: many_to_one ICriteria Query Problem
PostPosted: Thu May 11, 2006 10:29 am 
Newbie

Joined: Thu May 11, 2006 5:07 am
Posts: 1
i need help
please tell me how to query in this way
Hibernate version:1.02


Mapping documents:
(1)
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="BusinessObject.ChatInfoEO,BusinessObject" table="ChatInfo">
<id name="ChatId" column="ChatId" type="String">
<generator class="assigned" />
</id>
<property name="ChatContent" column="ChatContent" type="String" length="40" />
<property name="ChatDate" column="Chatdate" type="DateTime" />
<many-to-one name="UserInfo" column="UserId" class="BusinessObject.UserInfoEO,BusinessObject" />
</class>
</hibernate-mapping>

(2)
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="BusinessObject.UserInfoEO,BusinessObject" table="UserInfo">
<id name="UserId" column="UserId" type="String">
<generator class="assigned" />
</id>
<property name="UserName" column="UserName" type="String" length="40" />
<property name="UserAge" column="UserAge" type="System.Int32" />
<property name="UserBirth" column="UserBirth" type="DateTime" />
<property name="UserFax" column="UserFax" type="String" length="40" />

</class>
</hibernate-mapping>







i used ICriteria to query

Code :
ICriteria criteria = session.CreateCriteria(typeof(ChatInfoEO));
criteria.Add(Expression.Like("UserInfo.UserName","2"));
IList list = criteria.List();

[/ssib]

[b]
Exception occur
"could not resolve property:UserInfo.UserName of :BusinessObject.ChatInfoEO"


Name and version of the database you are using:

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:


Top
 Profile  
 
 Post subject: Re: many_to_one ICriteria Query Problem
PostPosted: Fri May 12, 2006 7:45 pm 
Newbie

Joined: Sun Aug 28, 2005 10:54 pm
Posts: 14
foxonline wrote:
Code :
ICriteria criteria = session.CreateCriteria(typeof(ChatInfoEO));
criteria.Add(Expression.Like("UserInfo.UserName","2"));
IList list = criteria.List();



The expression you specified uses an implicit join between the ChatInfoEO and UserInfo classes. Implicit joins are not supported by the ICriteria interface and the style of property access you used will only work when dereferencing components (e.g. UserInfo is mapped as a component, not a class).

I believe the following criteria will achieve your desired behavior:

Code:
session.CreateCriteria(typeof(ChatInfoEO))
.CreateCriteria("UserInfo")
.Add(Expression.Like("UserName","2"))
.List()


See http://www.hibernate.org/hib_docs/nhibernate/html/querycriteria.html for more information.


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.