• Post Reply Bookmark Topic Watch Topic
  • New Topic

Handling Transaction in Stateless session bean  RSS feed

 
amit ang
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Everybody,
Iam trying to execute a statless session bean. I have a method XXX, in which i use two SQL for insert of records, in two different tables. Now, what i want is, if the first SQL execeutes sucessfully and the second raises exception, then both there should be a rollback on both of the SQL statements.
I have tried using Required in the Deployment Descriptor, But that doesn't work.
I want the container to handle this situation.
Iam using weblogic 6.1 eval copy.
Thanks in Advance.
Amit
 
Matthew X. Brown
Ranch Hand
Posts: 165
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'd ask this question on the javaranch bea weblogic question forum. They'll be able to handle it better.
 
Ram Dhan Yadav K
Ranch Hand
Posts: 321
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Amit,
According to EJB specification.
If you can have two scenarios
1) Container Managed TRANSACTION
2) Bean Managed TRANSACTION (Not Persistance)
If Container Manged transaction:
Folow these steps:
a) You execute the first SQL statement.
b) You execute the second SQL statement.
c) Catch the SQLException and invoke 'setRollBackOnly()' method.
This should solve your problem.
If Bean Managed Transaction:
Follow these steps:
a)Get user transaction and start the transaction using 'trans.begin()'
a) You execute the first SQL statement.
b) You execute the second SQL statement.
c) Catch the SQLException and invoke 'trans.rollback()' method.
This should solve your problem.
Hope this helps.
thanks,
Ramdhan YK

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!