-->
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.  [ 1 post ] 
Author Message
 Post subject: Wrong update in table column
PostPosted: Thu Apr 18, 2013 6:23 am 
Newbie

Joined: Thu Apr 18, 2013 5:58 am
Posts: 1
I'm stucked with a problem I really cannot understand. Here's the situation.

I have a table called Merchant. Columns are MerchantId(int, autogenerated), AvailableAmount (float), GivenAmount(float). When a merchant gives its credit to someone else I have to decrease AvailableAmount column and increase the GivenAmount one. The method I use to do that is the following:

Code:
protected void deductFromMerchant(Merchant merchant, float amount){
      float merchantAvailable = merchant.getAvailableAmount();
      float merchantGiven = merchant.getGivenAmount();

      merchant.setAvailableBeenz(merchantAvailable - amount);
      merchant.setGivenBeenz(merchantGiven + amount);
      
      session.merge(merchant);
      log.info("merchant available now " + merchant.getAvailable());
   }


The output of the logger print the correct updated amount. The problem is that when I commit the transaction the values stored in the Available column are wrong, while the ones in GivenAmount are updated correctly. In particular if the Available amount is e.g. 90 and I try to deduct 4 units, the valued stored in the db remains 90. On the contrary if i deduct 6 units, the updated value is 80. Some strange kind of approximation I would say...
Notes:
- the GivenAmount column is updated correctly
- the loggers shows the correct available amount
- the session I use is already open
- the method is included in a transaction
- the method setAvailableBeenz is called only in this function
- i tried using saveorupdate instead of merge, clearing the session, clearing all the instances of Merchant included in the session, but the result is the same

Thanks in advance


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.