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 mathematical operators
PostPosted: Thu Dec 18, 2008 5:31 pm 
Beginner
Beginner

Joined: Mon Feb 04, 2008 7:36 pm
Posts: 31
Is it possible to do math in a detached criteria?

Something like this?

DetachedCriteria mv = DetachedCriteria.For<Asset>()
.Add(Subqueries.PropertyIn("ID", assetIDCriteria))
.CreateAlias("Security", "security")
.SetProjection("security.Price * Asset.Balance");

Obviously the project here does not work but I am looking for the equivalent from a detached criteria. We do a lot of custom list filtering so it would very difficult to write hql.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 19, 2008 6:12 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
You can project direct sql in a criteria:

crit.SetProjection( Projections.SqlProjection( ) )


If that's what you're looking for.

_________________
--Wolfgang


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 19, 2008 10:57 am 
Beginner
Beginner

Joined: Mon Feb 04, 2008 7:36 pm
Posts: 31
wolli wrote:
You can project direct sql in a criteria:
crit.SetProjection( Projections.SqlProjection( ) )


Isnt SqlProjection dbms specific? I am trying to remain vendor agnostic.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 19, 2008 12:16 pm 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
I assume that depends on your sql. If you do simple arithmetic, it should be possible to do that vendor independant. Another approach might be computed properties.

_________________
--Wolfgang


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.