• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Transactional attribute question....

 
Ranch Hand
Posts: 257
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 977
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, I tried it, and it works. Thanks!
SAF
reply
    Bookmark Topic Watch Topic
  • New Topic