-->
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: [CRITERIA] Join without foreign key
PostPosted: Fri May 30, 2008 10:29 am 
Beginner
Beginner

Joined: Mon Oct 01, 2007 6:23 am
Posts: 20
Hi,

Id like to add result for one Table joining another, but the join columns is to a primaryKey for the second table.
Example:

Code:
User:
id
userInfo
loginId
firstName
lastName

Logins
id
loginId
firstName
lastName


the criteria query concern User class, if I get 2 rows, Id like to add to add lastName firstName for identical loginId

sql query could be like:
Code:
select u.id,u.userInfo, u.loginIf, l.firstName,l.lastName  FROM User u LEFT JOIN Logins l on u.loginId = l.loginId


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 02, 2008 7:41 am 
Beginner
Beginner

Joined: Mon Oct 01, 2007 6:23 am
Posts: 20
any idea. .?

thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 02, 2008 8:11 am 
Beginner
Beginner

Joined: Mon Oct 01, 2007 6:23 am
Posts: 20
any idea. .?

thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 09, 2008 9:54 am 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
One idea is to have two results that dump their results into a set. Merge the set of the queries, and you have the results that you want.

Not the most elegant of solutions, but I've seen it done, and it works.

Here's a good tutorial on the Criteria API that you are using, if you're interested:

http://jpa.ezhibernate.com/Javacode/learn.jsp?tutorial=09howtousethecriteriaapi

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 09, 2008 10:51 am 
Beginner
Beginner

Joined: Mon Oct 01, 2007 6:23 am
Posts: 20
thanks a lot Cameron ..


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 10, 2008 9:28 pm 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
Well, it's not the most elegant solution, but it IS a solution, and sometimes, that's better than no solution at all.

Good luck!

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


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.