java - Hibernate data consistency -
i have java-servlet application +hibernate + streaming server
flow:
- user login begin video streaming
- decrement abonament minutes in data base every 2 seconds
- if minutes < 0 send request new minutes(response may after long time, if continue decrement )
problem:
appears data consistency problem, other words while decrementing minutes, ex: user.setminutes(user.getminutes() - 2)
may not see changes maded new minutes response, , minutes corrupted
i thought sollution create new hibernate transaction , commit every time when change minutes, didn't worked:
transaction t = session.begintransaction(); user.setminutes() session.flush(); t.commit();
question:
how solve problem, when each change recent data?
the hibernate session caches entities in memory (in case user
entity). it's not enough create new transaction changing remaining minutes, have reload changes made other tasks (addditional minutes request). can achieve calling refresh()
:
session.refresh(user); user.setminutes(user.getminutes() - 2); session.flush();
Comments
Post a Comment