-->
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.  [ 1 post ] 
Author Message
 Post subject: QBE sort on reference member's properties, possible and how?
PostPosted: Sat Feb 11, 2006 12:28 pm 
Beginner
Beginner

Joined: Fri Jan 07, 2005 11:07 am
Posts: 30
Did quite research on this forum for a solution, but failed to find any clue how to do it. Forgive me if it is a repeated or stupid question.

I need to do QBE to find records of class Contact which has two properties defined as:

Code:
<property name="contactDate" column="CONTACT_DATE"
        type="date" not-null="true"/>

<many-to-one name="employee" column="EMPLOYEE"
        class="Employee" lazy="false"/>      


"employee" is actually a one-to-one relationship. Employee are stored in
another table. Employee has a property called name.

I can retrieve and display Contact records together associated
Employee records in a single call to crit.list() (crit is a Criteria object)

I want to do sorting. I can sort on non-reference property contactDate
correctly. However I dont know how to sort on Employee.name.

The following is my code to get Contact and Employee records. "example"
is a Contact object.

Code:
       
Example target = Example.create(example).enableLike(MatchMode.ANYWHERE);
Criteria crit0 = getSession().createCriteria(Contact.class).add(target);
crit0.createCriteria("employee").add(Example.create(example.getEmployee()).enableLike(MatchMode.ANYWHERE));
crit0.addOrder(Order.asc("contactDate"));
List list = crit0.list();



Thanks for reading and thanks for your input!


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

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.