-->
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 (sum) and updates
PostPosted: Sat Apr 29, 2006 2:47 pm 
Beginner
Beginner

Joined: Wed Apr 05, 2006 3:19 pm
Posts: 43
How does the setup look like?

I have an object "Something". This has a set of "Items". I'm listing the items of "Something" on a web page.

- Sidenote - The "sum of values" is a formula property. So it's not in the database.
Code:
Sum of values: X

List:
Item 1 - value1
Item 2 - value2



What is the configuration?

Something:
Code:
<class name="Something" table="somethings">
<cache usage="read-write" />
      <id name="somethingID" column="somethingID">
            <generator class="native" />
        </id>
<property name="sum"
           insert="false"
           update="false"
           formula="(SELECT COALESCE(SUM(i.value), 0) FROM items i WHERE i.somethingID = somethingID))"
        />
<set name="items" inverse="true" cascade="all-delete-orphan" order-by="somethingID">
         <cache usage="read-write" />
          <key column="somethingID" on-delete="cascade" />
          <one-to-many class="Items" />
      </set>
</class>



What's am I trying to do?

I'm doing three things:
Code:
1) Show a page with items, together with a sum of it's values (the formula property of "something".
2) I update a value of an Item and click the update button.
3) Perform the update and reload the page with the correct values and sum

This last step needs a little explanation: If I click the "update" button,
1) a transaction is started
  2) the values are updated (item.setValue...)
  3) then I build the page with Something.getSum() in it
  4) ... and I add the Items (each item with item.getValue())
5) I commit the transaction



What is the problem?

The values get updated and are displayed CORRECTLY, but the sum doesn't get updated until I reload the page once more. (and it retrieves the committed values from the database with the sum formula)


What's my own view on this?

The item values get displayed correctly, because I set them with the Setter method. That way, they get updated in memory. Too bad, the transaction hasn't been committed yet, so Something.getSum() still has the old value in memory.


What's the question then?

I wonder if it's possible to tell hibernate to run something's "sum formula" on the items in memory (that are already updated). I can't play with the transaction, else it all gets screwed up and hibernate complains about a closed session etc. So that's not a solution.

_________________
Don't forget to rate my post if it helped. :)


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 04, 2006 12:57 pm 
Beginner
Beginner

Joined: Wed Apr 05, 2006 3:19 pm
Posts: 43
Anyone?

_________________
Don't forget to rate my post if it helped. :)


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 04, 2006 1:14 pm 
Expert
Expert

Joined: Tue Apr 25, 2006 12:04 pm
Posts: 260
formula values are updated at load time. So i guess in your case page refresh is working because of reloading.


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.