Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Transactional attribute question....  RSS feed

 
SAFROLE YUTANI
Ranch Hand
Posts: 257
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I have a stateless session bean with the following two methods:

public void createGoal(){
  Connection c =   datasource.getConnection()
  connection.executeUpdate();
  addObjectives();
}
public void addObjectives(){
  Connection c = datasource.getConnection()
  connection.executeUpdate()
}

So essentially, createGoal() calls addObjectives() once it finishes performing its jdbc work. This calling scheme represents a single transaction, so, if anything in addObjectives() fails, then all work performed in createGoal() must be rolled back. I'm not handling transactions explicitly because I want to use transactional attributes at the method-level to handle them for me. My question is this: If the transactional attribute for both methods is specified as REQUIRED, does addObjectives() become part of the transaction from createGoal() even though both methods are using different connection objects from the same data source?
SAF
[ March 12, 2002: Message edited by: SAFROLE YUTANI ]
 
Marcos Maia
Ranch Hand
Posts: 977
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
the answer is no.
The way to propagate a transaction on 2 method calls as you need is using UserTransaction interface, you must notice that for stateless session beans transactions must be started and completed within the same method call, so for your case you�re gonna have to use statefull session beans.
You can use this sintax:
1 - to start a transaction:

2 - than to commit the transaction you can use:
 
SAFROLE YUTANI
Ranch Hand
Posts: 257
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah, I ran into this problem last night and I think instead of placing the jdbc code in my bean, I'd rather create a DAO class that encapsulated the jdbc manipulation.
thanks,
SAF
 
Kareem Qureshi
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
You can let ur method throw an exception and then put ur code in try/catch block and in catch block use the ejb.SessionContext and call the setRollbackOnly() This will also solve ur problem i think. please let me know about the results.
Thanks
Kareem
 
SAFROLE YUTANI
Ranch Hand
Posts: 257
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, I tried it, and it works. Thanks!
SAF
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!