• 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 all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

Database Transactions  RSS feed

Ranch Hand
Posts: 418
  • 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?
sharp shooter, and author
Posts: 1913
  • 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...
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!