Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

transaction in Container managed session bean  RSS feed

 
haris hameed
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I have a session bean having transaction-type attribute as "Container" and transaction-attribute as "Required" .
The session bean has a method which update a field in the database table thru DataBase connection and then iam explicitly throw an EJBException to make the database update to roll back (just to check the "Required" transaction).
When I call this Session Bean from a standalone client java class
iam getting the TransactionRolledBack Exception in the client side ,but the database operation is not getting rolled back.
Can any one u friends please help me in this regards ?.
i have my method code here
// this is the method in the session bean
public void updateAndThrow(String str,int price){
System.out.println("from callerbean requires new" + price);
String updateStatement = "update orderbeantable1 set ord_prc =? where ord_id = ?" ;
PreparedStatement prepStmt = con.prepareStatement(updateStatement);
prepStmt.setInt(1, price);
prepStmt.setString(2, str);
prepStmt.executeUpdate();
prepStmt.close();
// explicitly throwing EJB EXception so that
// the above sql operation may get rollback
if (true) {
throw new EJBException();
}
}
Thanks
- haris .
 
Craig Jackson
Ranch Hand
Posts: 405
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am new to EJB/J2EE, but Based on your description of the problem, it sounds like you should be using BEAN managed transactions instead of CONTAINER managed transactions for your session bean or even in your client code. I believe you should use the javax.transaction.UserTransaction interface to programmatically control the transaction.
Craig
 
haris hameed
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi jack
Thanks for ur reply ,
But iam sure iam using Container Managed Transaction
"<transaction-type>Container</transaction-type>"
and also in my client code iam not using the UserTransaction .
- Haris
 
Naveen Kuppili
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by oharis:
When I call this Session Bean from a standalone client java class
iam getting the TransactionRolledBack Exception in the client side ,but the database operation is not getting rolled back.

You need to get the connection from a datasource which supports your container configuration. For example on Weblogic, you need to create a "TX Datasource" (Transactional Datasource) and not a normal Datasource to support this sort of transactions.
 
haris hameed
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Naveen
Yes now its working (the database operation is getting rollbacked ) . thanks a lot .
Thanks to everybody .
- Haris
 
Simon Brown
sharp shooter, and author
Ranch Hand
Posts: 1913
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi "oharis",
We have a naming policy here at JavaRanch where all publicly displayed names take the form, "Firstname Surname". Could you please edit your profile to bring it into line?
Thanks in advance and we hope that you enjoy your stay at the ranch!
Cheers
Simon
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!