java - Hibernate data consistency -


i have java-servlet application +hibernate + streaming server

flow:

  1. user login begin video streaming
  2. decrement abonament minutes in data base every 2 seconds
  3. 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

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -