-->
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.  [ 4 posts ] 
Author Message
 Post subject: DetachedCriteria and simple joins
PostPosted: Mon May 04, 2009 3:59 pm 
Newbie

Joined: Mon Mar 23, 2009 3:20 pm
Posts: 4
Let's say I have an Employee class and a Request class. The request class has a RequestedBy field which is joined to an Employee class (which is represented by a database view). My Request class does not have any coded associations between RequestedBy and Employee. I am trying to create a reporting query via DetachedCriteria that joins the RequestedBy field to the Employee.NetworkID field.

How would I accomplish such a task? I have been fighting with this for quite some time. Thanks for any help.


Top
 Profile  
 
 Post subject: Re: DetachedCriteria and simple joins
PostPosted: Tue May 05, 2009 2:22 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
With criterias you can only use a subquery for filtering the result set. If you need a real join, you have to use HQL. Can you post the SQL you need ?

_________________
--Wolfgang


Top
 Profile  
 
 Post subject: Re: DetachedCriteria and simple joins
PostPosted: Tue May 05, 2009 12:00 pm 
Newbie

Joined: Mon Mar 23, 2009 3:20 pm
Posts: 4
Thanks for your reply.

SELECT R.RequestId, R.EventName, R.RequestedBy, E.FullName
FROM dbo.Request R
LEFT OUTER JOIN dbo.Employee E ON E.NetworkID = R.RequestedBy

I thought I could somehow add new associations in DetachedCriteria.


Top
 Profile  
 
 Post subject: Re: DetachedCriteria and simple joins
PostPosted: Tue May 05, 2009 12:26 pm 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
That kind of query is not possible with criterias (at least in NH 1.2, but I can't remember changes there in 2.0 or 2.1). You can only do subqueries qith criterias.

But you can always use a HQL query:

Code:
select r.RequestId, r.EventName, r.RequestedBy, e.Fullname
from Employee e, Request r where e.NetworkId = r.RequestedBy

_________________
--Wolfgang


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