-->
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: how to optimize select of api criteria
PostPosted: Wed Jan 02, 2008 9:50 am 
Newbie

Joined: Wed Feb 01, 2006 10:16 am
Posts: 13
I would like to optimize the generated select of api criteria


With 2 tables


Criteria crit = this.getSession().createCriteria(T1.class);
crit.createCriteria(T2.class);
crit.add(Restrictions.eq(T2NAME,"TOTO"));


Api generate sql like:

SELECT T1.*,T2.* FROM T1 INNER JOIN T2 ON T1.C1=T2.C2 where T2.T2NAME = 'TOTO';

But how to specify to criteria to recover only one or more property into T1 objet

SELECT T1.C1, T1.C4 FROM T1 INNER JOIN T2 ON T1.C1=T2.C2 where T2.T2NAME = 'TOTO4;

i test setResultTransformer(Transformers.aliasToBean(target))


Top
 Profile  
 
 Post subject: hql
PostPosted: Thu Jan 03, 2008 4:24 pm 
Expert
Expert

Joined: Mon Nov 26, 2007 2:29 pm
Posts: 443
assuming that T1 and T2 are already joined i the mapping files, and that there is a property T1.getT2()

Code:
select t1.c2, t1.c4
from T1 t1
where t1.t2.name='TOTO'


you can put this into an HQL query and treat the array of objects it returns

_________________
Gonzalo Díaz


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.