-->
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: <property formula="?" />
PostPosted: Wed Dec 03, 2003 6:34 pm 
Regular
Regular

Joined: Fri Sep 05, 2003 12:01 am
Posts: 80
Location: Bogot
Hi!

I'm trying to use a calculated property (formula) but had only luck with simple things like adding up attributes:


Assuming a class that has the quantity, unit_cost and unit_labor attributes, this will work:

Code:
<property formula="quantity * (unit_cost+ unit_labor)" />


But I would like to perform an SQL query like the following, which doesnt work.

Code:
select sum (quantity * (unit_cost+ unit_labor)) from table_X


From my understanding the documentation for http://www.hibernate.org/hib_docs/reference/html/or-mapping.html#or-mapping-s1-7 Hibernate 2.1 (the version I'm using) talk about formula beign an SQL expression... but its not really clear on the semantics, variable scope etc...

Any ideas or workarounds?

_________________
Mauricio Hern


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 03, 2003 8:58 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Why doesn't it work?

You may use any columns of the class' table in the formula.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 05, 2003 1:56 pm 
Regular
Regular

Joined: Fri Sep 05, 2003 12:01 am
Posts: 80
Location: Bogot
This works great:

Code:
<property
            name="item"
            type="long"
            update="true"
            insert="true"
            column="item"
        />

<!-- totalContractedPerItem is a strored procedure which has a number as input and a single row as output.  -->
  <property name="totalContracted"
        type ="float"
        update="false"
        insert="false"
        formula="(select * from totalContractedPerItem(6880))"
        />


BUT I dont want a literal (6880), I would need to pass as an argument the item property. Is that feasible? Any other better way to do it?

Thanks in advance

_________________
Mauricio Hern


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.