• Post Reply Bookmark Topic Watch Topic
  • New Topic

Database Transactions

 
Siegfried Heintze
Ranch Hand
Posts: 417
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I had assumed that J2EE specified the concept of a database transaction like COM+ does but I cannot find an example.
Can someone point me to an example of a database transaction with rollback in J2EE?
 
Simon Brown
sharp shooter, and author
Ranch Hand
Posts: 1913
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
J2EE treats transactions at a slightly higher level than the database. In essence, there are various ways in which the transactionality of EJB components can be defined - both programmatically and declaratively.
When interacting with the database through JDBC, instead of using a "database transaction" you would use a JTA (Java Transaction API) transaction. If you have defined your beans to use container managed transactions (CMT), then this is done for you behind the scenes. If you are using bean managed transactions (BMT, on session beans only) then you have to "look up" a transaction object (of type UserTransaction) and explicitly start and commit (or rollback) it.
From within this context, by looking up and using a transactional DataSource, the transactional context can be carried forward. Therefore, if you rollback the JTA transaction, the underlying database transaction will also get rolled back.
I really hope that makes sense!
As for examples, take a look at the J2EE Tutorial on the java.sun.com site, or even the documentation that ships with BEA WebLogic (at www.weblogic.com) as this also has some "tutorial" style documentation.
Hope that helps...
Simon
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!