-->
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 reference multi tables in Projections.sqlProjection
PostPosted: Tue Jun 08, 2010 3:06 pm 
Newbie

Joined: Tue Jun 08, 2010 2:43 pm
Posts: 2
If I have two tables:
A(A1,A2)
B(B1,B2)

I need write Projections like :
Code:
DetachedCriteria ACriteria=DetachedCriteria.forClass(A.class)
.createAlias("B","b")
.setProjection(Projections
                       .sqlProjection("(sum(A.A1) / B.B1) as test"
                                                 , new String[]{"test"}
                                                 , new Type[]{Hibernate.DOUBLE}))

inside sqlProjection, {alias} can be used for entiy A,but "b" or "B" can not be used to reference entity B


how to write this kind of sqlProjection?
Thank you very much!


Top
 Profile  
 
 Post subject: Re: how to reference multi tables in Projections.sqlProjection
PostPosted: Thu Jul 15, 2010 4:17 pm 
Newbie

Joined: Thu Jul 15, 2010 3:59 pm
Posts: 1
I am trying to figure this out as well. Looking at the code, it just does a string replace on {alias} and there are no real smarts to it.

I've tried doing something like the following, where I try to get the alias, but it would seem that the word Alias is used all over the place for different purposes in the Criteria API.

Code:
Criteria rootCrit = session.createCriteria(Foo.class);
Criteria subCrit = root.createCriteria(Child.class);

rootCrit.setProjection(Projections.sqlProjection(String.format("case when %s.FIELD > 99 then 1 else 0 end as flag", subCrit.getAlias()), new String[] {"flag"}, new Type[] {Hibernate.INTEGER}));



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.