-->
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.  [ 7 posts ] 
Author Message
 Post subject: How to search the using the child value
PostPosted: Tue Jun 13, 2006 7:17 am 
Newbie

Joined: Tue Jun 13, 2006 7:10 am
Posts: 4
Hi,

I have defination as following (sample only). I could not figure out how to search the order using the StatusName as search expression :

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="Order, AppLib" table="Order">

<id name="ID" column="ID">
<generator class="identity" />
</id>

<property name="CreateBy"></property>
<property name="CreateDate"></property>
<property name="UpdateBy"></property>
<property name="UpdateDate"></property>
<property name="TS" insert="false" update="false"/>

<many-to-one name="Status" class="Status, AppLib" column="StatusID"/>

</class>

<class name="Status, AppLib" table="Status">

<id name="StatusID" column="StatusID">
<generator class="identity" />
</id>

<property name="StatusName"></property>

</class>
</hibernate-mapping>

Regards,

Boon Seong


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 13, 2006 10:49 am 
Expert
Expert

Joined: Fri May 13, 2005 5:56 pm
Posts: 308
Location: Santa Barbara, California, USA
Code:
session.CreateCriteria(typeof(Order))
    .CreateCriteria("Status")
        .Add(Expression.Eq("StatusName", myStatusName))
    .List();


haven't debugged the code but this is a starting point.

-devon


Top
 Profile  
 
 Post subject: How to search subcriteria
PostPosted: Wed Jun 14, 2006 2:19 am 
Newbie

Joined: Tue Jun 13, 2006 7:10 am
Posts: 4
devonl, thanks for your reply.

How do I do a sorting based on StatusName then ? I tried to add the Order.Asc to the subcriteria(status) but it return error saying that subcriteria cannot be sorted. My code as following :

ICriteria statusCriteria = session.CreateCriteria(typeof(Order))
.CreateCriteria("Status"));

statusCriteria.AddOrder(Order.Asc("StatusName"));


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 14, 2006 10:25 am 
Expert
Expert

Joined: Fri May 13, 2005 5:56 pm
Posts: 308
Location: Santa Barbara, California, USA
yes, that is a limitation of the ICriteria interface currently. if you need to sort on the StatusName, then you will have to use HQL or an embedded SQL query.

-devon


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 14, 2006 11:34 am 
Expert
Expert

Joined: Fri May 13, 2005 5:56 pm
Posts: 308
Location: Santa Barbara, California, USA
hmmm, i saw this in another thread:

Quote:
criteria.CreateCriteria("Batch", "batch").Add(NH.Expression.Expression.Eq("Submitter.Branch.Id", Convert.ToInt32(BranchCode)));

i wonder if you could do something like:

Code:
criteria.CreateCriteria(typeof(Order))
    .Add(Expression.Eq("StatusName", myStatusName))
    .AddOrder(Order.Asc(Status.StatusName))
    .List();

or something similar. if you try it, can you please report back to the board?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 15, 2006 6:37 am 
Newbie

Joined: Tue Jun 13, 2006 7:10 am
Posts: 4
nope... the method does not work


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 15, 2006 9:52 am 
Expert
Expert

Joined: Fri May 13, 2005 5:56 pm
Posts: 308
Location: Santa Barbara, California, USA
okay, then you are relegated to HQL i'm afraid.

-devon


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