-->
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: DetachedCriteria projection support expression?
PostPosted: Mon May 10, 2010 1:31 am 
Senior
Senior

Joined: Tue Sep 13, 2005 2:01 am
Posts: 137
class Foo {
Boolean negative;
Integer value;
}

we want to sum the value like the following:
if negative, negate the value and add to the total.
otherwise, add to the total.

case negative when true then -1 else 1 end

select sum((case negative when true then -1 else 1 end) * value) from Foo;

is it possible to use Criteria API to add projection for this?

Thanks
Dave


Top
 Profile  
 
 Post subject: Re: DetachedCriteria projection support expression?
PostPosted: Mon May 10, 2010 3:22 am 
Newbie

Joined: Tue May 04, 2010 8:15 am
Posts: 5
Hello Dave,

Try this one

Code:
criteria.SetProjection(Projections.Sum(Projections.SubQuery(DetachedCriteriaObj)));


Top
 Profile  
 
 Post subject: Re: DetachedCriteria projection support expression?
PostPosted: Tue May 11, 2010 2:10 am 
Senior
Senior

Joined: Tue Sep 13, 2005 2:01 am
Posts: 137
Hello,

I looked at API. The Projections.SubQuery() does not exist. Also
the Projections.sum() takes a property name only. Thanks!


Top
 Profile  
 
 Post subject: Re: DetachedCriteria projection support expression?
PostPosted: Tue May 11, 2010 4:58 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Well, this is really the wrong forum. You should post this question on the Hibernate User forum.
Just an idea though - have you looked at Projections.sqlProjection?

--Hardy


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.