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.  [ 3 posts ] 
Author Message
 Post subject: Help with a HQL issue
PostPosted: Fri May 08, 2009 9:26 am 
Beginner
Beginner

Joined: Thu Aug 14, 2008 5:31 pm
Posts: 20
Hi,

I have two classes :

class Source and class Post, which has a many to one relationship with Source. In the mapping of Post I therefore have something like :

<many-to-one class="Comp.Source,Compname="theSource" cascade="all-delete-orphan" column="SourceID" />

Now in HQL I'm trying to get a list of Source, only I want to limit this list to the Source entities that are associated to Post entities (in other word I want to do an inner join).

So far I've got this :

ICriteria sourceCriteria = SessionManager.GetCurrentSession().CreateCriteria(typeof (Source));
sourceCriteria.SetMaxResults(10).List<Source>();

Now how do I limit this to only the Source associated to a Post ?

Thanks

PS: the code is C# but I'm happy with Java equivalent.


Top
 Profile  
 
 Post subject: Re: Help with a HQL issue
PostPosted: Fri May 08, 2009 9:34 am 
Beginner
Beginner

Joined: Tue Mar 10, 2009 11:50 pm
Posts: 23
You should add not-null restriction for Posts in the Source criteria, like

criteria.add( Restrictions.isNotNull("Posts"))

_________________
Cheers,

Vinod
We act as though comfort and luxury were the chief requirements of life, when all that we need to make us happy is something to be enthusiastic about


Top
 Profile  
 
 Post subject: Re: Help with a HQL issue
PostPosted: Fri May 08, 2009 9:41 am 
Beginner
Beginner

Joined: Thu Aug 14, 2008 5:31 pm
Posts: 20
But I don't have a Posts property on Source and I'd like to keep it like this.

However I do have a property of type Source (theSource) in the Post class. Is there not a way then to join using this property ?


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