Hi,
I'm looking for the efficient solution of following problem using hibernate:
Scenario:
- Two node cluster
- Each node concurrently adds some value to "price" in the same "account"
SQL Solution:
state before: price=1 for account id=4
NODE1: stm1.execute("update account set price=price+3 where id=4")
NODE2: stm2.execute("update account set price=price+8 where id=4")
state after: price=12 for account id=4
Hibernate Solution:
state before: price=1 for account id=4
NODE1: trans1.start()
NODE1: sess1.load(account1, 4)
NODE1: account1.price=account1.price+3
NODE1: trans1.commit()
NODE1: trans2.start()
NODE1: sess2.load(account2, 4)
NODE1: account2.price=account2.price+8
NODE1: trans2.commit()
state after: price=12 for account id=4
I suppose Hibernate solution will use at minimum 4 SQL queries in transaction, but SQL solution needs only two simple updates.
Is there better solution for this scenario?
I've considered using JBossCache but, i'm afraid that cluster communication overhead could be bigger then Hibernate overhead.
Thang you for any ideas
David
|