-->
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.  [ 6 posts ] 
Author Message
 Post subject: hibernate join
PostPosted: Sun Sep 17, 2006 4:30 am 
Newbie

Joined: Thu Dec 01, 2005 5:58 pm
Posts: 10
hi i have a join sql and i am getting stuck and hopefully someone can give me a hand on this.

i have two class

User
{
String firstName;
String lastName;
Company company;
}

Company
{
Integer companyID;
String name;
}

i mapped them correctly and i am able to retrieve the object correctly.

if i just try to order them by User.firstname and User.lastname, everything is working great.
Query query = session.createQuery("from User order by lastName, u.firstName");


however, i need to order them by Company.name, User.lastName, User.firstName. what's the best way of doing this. i research on the web and come up w/ the following solution.
Query query = session.createQuery("from User u join u.company c order by c.name, u.lastName, u.firstName");

however, now i am not sure what kind of object is this. i can't print or use the result. is this the best way of doing the order by.

thanks for any help


Top
 Profile  
 
 Post subject:
PostPosted: Sun Sep 17, 2006 1:18 pm 
Senior
Senior

Joined: Sun Jun 04, 2006 1:58 am
Posts: 136
you will get list of User object with company feteched with each user.....

_________________
Don't forget to rate


Top
 Profile  
 
 Post subject: user object
PostPosted: Mon Sep 18, 2006 12:06 am 
Newbie

Joined: Thu Dec 01, 2005 5:58 pm
Posts: 10
thanks for the reply. however, i don't think it is an user object.

i tried to use instanceof and it shows that it is not user object.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 18, 2006 3:04 am 
Beginner
Beginner

Joined: Mon Nov 22, 2004 11:21 am
Posts: 42
What you get is a List of Object-Arrays. Each Object-Array has two Objects: User and Company. If you want only the user, then you have to specify a select-clause:

Code:
select u from User u join u.company c order by c.name, u.lastName, u.firstName

Regards,
Georg

P.S.: Please rate this posting if it helps you solving the problem

_________________
Real programmers confuse Halloween and Christmas because OCT 31 = DEC 25


Top
 Profile  
 
 Post subject: thanks
PostPosted: Wed Sep 20, 2006 9:41 pm 
Newbie

Joined: Thu Dec 01, 2005 5:58 pm
Posts: 10
thanks gskempes, scarface. now it is working great.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 21, 2006 11:40 am 
Senior
Senior

Joined: Sat Nov 27, 2004 4:13 am
Posts: 137
why don't you just use:

Code:
from User u order by u.company.name, u.lastName, u.firstName
[/code]

_________________
don't forget to credit!

Amir Pashazadeh
Payeshgaran MT
پايشگران مديريت طرح
http://www.payeshgaran.co
http://www.payeshgaran.org
http://www.payeshgaran.net


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