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