-->
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: stale formula
PostPosted: Thu Jun 08, 2006 12:29 am 
Newbie

Joined: Mon Apr 03, 2006 1:38 am
Posts: 11
I've got an Order object that has a collection of Items and a formula property (Order.TotalPrice) that calculates the total price of the Items in an Order. If I update the price of one of the Items in an Order with session.Update(Item) then do Order.TotalPrice I don't get an updated total. If I do a session.Flush() before the Order.TotalPrice I get the updated total.

Is this a bug? Or am I doing something wrong?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 08, 2006 2:02 am 
Expert
Expert

Joined: Fri May 13, 2005 5:56 pm
Posts: 308
Location: Santa Barbara, California, USA
you are doing something wrong unfortunately. :) think about it, the formula is calculated by the database when the object is instantiated. so the SQL can't run when the object is updated. you would have to call session.Flush() or maybe even session.Lock() to allow the SQL formula to be recalculated.

-devon


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 08, 2006 7:50 pm 
Newbie

Joined: Mon Apr 03, 2006 1:38 am
Posts: 11
I would have thought hibernate would take care of the flush and refresh the formula when you access the formula.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 09, 2006 12:29 am 
Expert
Expert

Joined: Fri May 13, 2005 5:56 pm
Posts: 308
Location: Santa Barbara, California, USA
unfortunately no. would need to call session.Refresh() after you save the object, or reload the object in a new session to get the formula to run. there is no way for NH to execute a read (formula) when session.Flush() (execpt for getting an id of a transient object that is made persistent).

-devon


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.