-->
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: Criteria joins and excluding unwanted entities
PostPosted: Wed Jan 30, 2008 10:23 pm 
Newbie

Joined: Sun Mar 20, 2005 10:40 am
Posts: 11
Location: London (UK)
Hibernate version: 3.2.5 GA
Hi there,

I'm trying to create a Criteria query that corresponds to the following HQL:
Code:
select new map(catalog as cat, artist as art) from Catalog catalog left join catalog.albums album left join album.artists artist where album.name = 'Aftermath'


So far the closest I've come is the following:
Code:
final Criteria criteria = session.createCriteria(Catalog.class);
criteria.createAlias("albums","alb");
criteria.add(Restrictions.eq("alb.name","Aftermath"));
criteria.createAlias("alb.artists", "art");
criteria.setResultTransformer(Criteria.ALIAS_TO_ENTITY_MAP);
final List<Map<String,Object>> map = criteria.list();


That works just fine, but of course I get three entities in each map entry, instead of the two entries of the original. I would like to exclude the unwanted album entity so that the generated SQL is equivalent to that produced for the HQL query, but cannot for the life of my figure out how to do so.

Any suggestions?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 31, 2008 8:08 am 
Newbie

Joined: Fri Jan 25, 2008 5:08 am
Posts: 3
hi,

try

setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 31, 2008 8:50 am 
Newbie

Joined: Sun Mar 20, 2005 10:40 am
Posts: 11
Location: London (UK)
quentUser wrote:
hi,

try

setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);


I don't follow - that will surely transform the returned results, which doesn't buy me anything over using a map and ignoring the elements that I don't want. I'm trying to avoid the inclusion of all those unwanted columns from the Album entity in the initial SQL join.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 29, 2008 5:32 am 
Newbie

Joined: Tue May 10, 2005 6:15 am
Posts: 4
I have the same problem. Any solution on this?


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.