I'm having a problem that's not Hibernate specific, though I'm using Hibernate and dont know if it has something builtin that can help. If this doesn't belong here then I apologize.
In general the problem is the following.
I have the following tables
TABLE A ----------- AMMOUNT : NUMBER
TABLE B ------------ PAYMENT_AMMOUNT : NUMBER
I would be adding payments to table B that have a many to one relationship with table A. The SUM of payments added cannot exceed AMMOUNT from table A. So before inserting I have to sum the payments I have thuse far and compare with AMMOUNT, this is fine but if another user makes an insert around the same time i'll potentially end up in an inconsistent state with payments exceeding my ammount.
My questions is how can I handle this is general and/or specifically with Hibernate.
I need a nudge in the right direction.
Regards, Daniel
|