Transaction question

This is a discussion on Transaction question within the Apache forums in Application Servers & Tools category; I am porting an application to container-managed JPA. In my EJB, I now have a function that does something like this: function CreateAccount() { Person p = new Person(); Address a = new Address(); .... em.persist(p); em.persist(a) .... } In my Web page that uses the EJB, I have added a transaction manager like this: InitialContext context = new InitialContext(); UserTransaction tx = (UserTransaction) context.lookup("java:comp/UserTransaction"); tx.begin(); myEjb.CreateAccount(); tx.commit(); my question is, if the call to em.persist(a) fails, will the persistence of p roll back? I'm going to test it out. Feel free to comment. Thanks, Eric -- View this message ...

Go Back   Application Development Forum > Application Servers & Tools > Apache

Object Mix

Register FAQ Calendar Search Today's Posts Mark Forums Read
  #1  
Old 09-17-2008, 10:49 AM
ericp56
Guest
 
Default Transaction question


I am porting an application to container-managed JPA.

In my EJB, I now have a function that does something like this:

function CreateAccount() {
Person p = new Person();
Address a = new Address();
....
em.persist(p);
em.persist(a)
....

}

In my Web page that uses the EJB, I have added a transaction manager like
this:

InitialContext context = new InitialContext();
UserTransaction tx = (UserTransaction)
context.lookup("java:comp/UserTransaction");
tx.begin();
myEjb.CreateAccount();
tx.commit();

my question is, if the call to em.persist(a) fails, will the persistence of
p roll back?

I'm going to test it out. Feel free to comment.

Thanks,

Eric
--
View this message in context: http://n2.nabble.com/Transaction-que...1p1095461.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.


Reply With Quote
  #2  
Old 09-17-2008, 05:33 PM
Pinaki Poddar
Guest
 
Default Re: Transaction question


> if the call to em.persist(a) fails, will the persistence of p roll back?


Yes.


--
View this message in context: http://n2.nabble.com/Transaction-que...1p1096608.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.


Reply With Quote
Reply


Thread Tools
Display Modes


All times are GMT -5. The time now is 08:54 PM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
vB Ad Management by =RedTyger=

In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.