-->
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.  [ 2 posts ] 
Author Message
 Post subject: Most efficient way to do a distinct with Criteria API?
PostPosted: Tue Feb 15, 2005 1:19 pm 
Pro
Pro

Joined: Fri Nov 19, 2004 5:52 pm
Posts: 232
Location: Chicago, IL
Hibernate version: 3.0beta4

I'm using the Criteria API to issue a query similar to the following. I found out how to use the setResultTransformer() method so that it only returns a single Reservation object for each Reservation object, rather than one for each Item (a reservation can have items in my data model). This is working fine.

Code:
Criteria c = s.createCriteria(Reservation.class)
   .setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY)
   .createAlias("items", "i")
   .add(Expression.like("i.name", itemName));

However, I'm wondering if maybe there is a more efficient or newer way to do this with the Hibernate 3.0 API since there is the new Projection API or what not. What I'm wondering is if there is a way to tell it to use a "distinct" in the SQL statement that it generates rather than presumably performing the filtering on the client side?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 15, 2005 3:30 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
in this case the distinct keyword will not give you distinct reservations, since it relies on the distinct SQL keyword

_________________
Emmanuel


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