0

we have a function with @Transactional and it has a if expression. when its true we must return list(with manipulated it!!) and in else expression we must Save a entity!! but when that return my list , it Update my list in Database.

  • we use else expression in a function with @Transactional(readOnly=true) but it doesn't work.
  • we use else expression in a function in the other Service Class with @Transactional(readOnly=true) but it doesn't work either

so we use session.envict(myobjects) to detach this Object !! but We don't think it's best way...

Is there a better way?

Anthony Raymond
  • 7,434
  • 6
  • 42
  • 59
  • you probably should edit your question to make it more readable and clearer. Otherwise your question might stay unanswered or deleted by the community – Anthony Raymond Jan 30 '17 at 13:10
  • @AnthonyRaymond tanks for edit – Mahdi khodabandelu Jan 30 '17 at 13:13
  • No problem, but you should edit again to make clear what you ask for – Anthony Raymond Jan 30 '17 at 13:14
  • `Readonly=true` should work, if it doesn't work, that's probably because you have another transaction already open and it is being reused. Otherwise, evict is your one way to prevent an update when the transaction is closed and commited. Usually you will want to avoid modifying an entity if it's not supposed to be persisted. – Guillaume F. Jan 30 '17 at 13:57

0 Answers0