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: Translate HQL to criteria?
PostPosted: Sat Apr 19, 2008 2:48 pm 
Regular
Regular

Joined: Fri Feb 18, 2005 3:34 am
Posts: 88
Location: Poland/Wrocław
How do I translate the following query to the criteria query?

Code:
select distinct d from Document d
  inner join d.Categories
  where :category in elements(d.Categories)

_________________
Please rate this post if you've found it helpfull
Roland


Top
 Profile  
 
 Post subject:
PostPosted: Sun Apr 20, 2008 2:48 am 
Regular
Regular

Joined: Fri Feb 18, 2005 3:34 am
Posts: 88
Location: Poland/Wrocław
In other words the question would look like:

How to create criteria that checks whether a given object (provided as parameter) is the one of associated collection in the persisted object.

More detailed: I have a persisted class (Document) that has associated collection of categories (DocumentCategory). Now I want to get documents that belong to given category.

_________________
Please rate this post if you've found it helpfull
Roland


Top
 Profile  
 
 Post subject:
PostPosted: Sun Apr 20, 2008 7:47 am 
Regular
Regular

Joined: Fri Feb 18, 2005 3:34 am
Posts: 88
Location: Poland/Wrocław
I think I've found how to achieve that. It seems extreemly simple so please anybody verify me if possible. The solution criteria looks like the following:

Code:
ICriteria criteria = session.CreateCriteria(typeof(Document));
object result = criteria
  .CreateCriteria("Categories")
    .Add(Expression.IdEq(categoryId))
  .List<Document>();


BTW: Is looks much easier than in case of HQL...

_________________
Please rate this post if you've found it helpfull
Roland


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.