-->
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: Criteria - how to use created Alias in sqlRestriction
PostPosted: Wed Nov 07, 2007 1:27 pm 
Newbie

Joined: Wed Nov 07, 2007 12:14 pm
Posts: 2
Hello,
by Criteria - how to use created Alias in Restrictions.sqlRestriction() ?
i tried this:
Code:
Criteria criteria = session.createCriteria(Transaction.class);
Criteria crl_criteria = criteria.createCriteria("currentRevisionLevel", "crl");
Criteria ttr_criteria =criteria.createCriteria("transactionType").createCriteria("revision","ttr");
criteria.add( Restrictions.sqlRestriction(crl_criteria.getAlias()+".id<"+ttr_criteria.getAlias()+".id"));
criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
criteria.setProjection(Projections.projectionList().add(Projections.rowCount()));

generated sql for this criteria:
Code:
SELECT count( * ) AS y0_
FROM banks_transaction this_
INNER JOIN banks_financial_transaction_type financialt2_ ON this_.transactionType = financialt2_.id
INNER JOIN banks_revision ttr3_ ON financialt2_.revision = ttr3_.id
INNER JOIN banks_revision crl1_ ON this_.currentRevisionLevel = crl1_.id
WHERE  crl.id < ttr.id

alias changed in generated sql from crl to crl1_ and from ttr to ttr3_ but on where clause it does not change

thanks
john


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 08, 2007 10:12 am 
Newbie

Joined: Wed Nov 07, 2007 12:14 pm
Posts: 2
should i do something else to run this Criteria ?


Top
 Profile  
 
 Post subject: Re: Criteria - how to use created Alias in sqlRestriction
PostPosted: Tue Sep 23, 2008 3:35 am 
Newbie

Joined: Thu Aug 28, 2008 3:31 am
Posts: 5
You cannot use alias in the sqlRestriction except the base table criteria.
eg.
session.createCriteria(Transaction.class,"baseAlias");
then , you can use this criteria in sqlRestirction as this:
"{alias}.xxProperty....", this {alias} will be replaced by baseAlias at runtime.

I feel so sad about this feature,too.


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.