0 Replies Latest reply on Mar 10, 2015 4:51 AM by jo jo

    Multiple hibernate user transaction

    jo jo Newbie

      Hi everybody,

       

      I am trying to implement multiple transactions in the same method in java on a web application with jboss and hibernate. I am working with seam 3 btw.

      So I know that basically you do: begintransaction -> commit / rollback -> close

      What I would like to do is to commit/rollback in a for loop. For a list of objects I am making updates and if everything went right I commit each object separately or I rollback.

      The problem is that I have already the same kind of errors: either the session is closed or invalid or the transaction is invalid or the objects are detached (if I clear the entitymanager).

      I tried a looooooooooooooooot of different things I found on the internet but none worked. The last thing I tried was to use the entitymanager: em.flush (if the updates went right => this works), but if there is a problem I tried to rollback (this is detaching the objects and the next flush doesn't work anymore in the for loop).

      So my question is: what is the right way to commit / rollback each object like this:

      for (Object obj : objects) { //Operations if(ok) { commit } else { rollback } }

      Thanks !