-
1. Re: Conversations, Transactions and Rollback
israel.bgf May 25, 2009 7:01 PM (in response to israel.bgf)@In EntityManager em; public void persistUser(User user, Stuff stuff){ try{ em.persist(user); //ok em.persist(stuff); // runtime in here error em.flush } catch(Exception e) { FacesMessage.instance().add("Error!"); return; //now i have a "ghost" user that will be persisted next time (if it suceeds) } }
Ops, i bugged the code. :)
-
2. Re: Conversations, Transactions and Rollback
israel.bgf May 25, 2009 8:08 PM (in response to israel.bgf)i tried something a bit different and i saw something very strange (nome more manual flushing):
@In EntityManager em; @Transactional public void persistUser(User user, Stuff stuff){ em.persist(user); //ok em.persist(stuff); // runtime in here error }
I invoke this method from my
backing-bean
(another Seam component that injects this one), in that bean i have:try{ bo.persistUser(user,stuff) }catch{ FacesMessage.instance().add("error"); } List<User> u = em.createQuery("from User").getResultList(); if(u.getSize() != 0) System.out.println("it should be like this");
--
I dont have users in my base, i try to persist but it fires an exception (
should be rolled back
). But when i do the search i find the user that i persisted(and shouldn't find).But.. it just find him for
one request
, if i search again afer this request, it is no more there (the way that it should work).Strange...
-
3. Re: Conversations, Transactions and Rollback
luxspes May 25, 2009 8:33 PM (in response to israel.bgf)You are more likely to get help if you post all you stack trace.
-
4. Re: Conversations, Transactions and Rollback
israel.bgf May 25, 2009 9:36 PM (in response to israel.bgf)Ops, sorry let me retype.
I dont have users in my base, i try to persist the stuff but its null so the entityManager fires a runtime exception. My backing bean catch this exception. At this time i suppose that the user that was persisted, was not, cause the transaction was rolledback (from the runtime exception on a transactional method), but it is still being retrivied from the database on that request. If i do a search after this, it is not there anymore.
Does the transaction only get rolled-back after the invoke-method phase? I thought that the BMT would rollback as soon the method finishes.
-
5. Re: Conversations, Transactions and Rollback
gonorrhea May 25, 2009 9:55 PM (in response to israel.bgf)I typically use CMT with EJB (SFSB as backing bean) but I believe that Seam managed tx's semantics are similar (i.e. like CMT).
stack trace = ERROR level (exceptions) logging in server.log
-
6. Re: Conversations, Transactions and Rollback
israel.bgf May 26, 2009 3:27 PM (in response to israel.bgf)I'm using BMT now with EJB, so i'm happy for now. But, i wanted to know if is it possible to use two Persistence Contexts, Seam Managed one with the EJB managed one to use the s:convertEntity. I dont want seam to use global transactions too, cause i dont want that him touch my EJBs.