wood burning stoves
The moose likes JDBC and Relational Databases and the fly likes Commiting a transaction from J2EE Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of The Software Craftsman this week in the Agile forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Commiting a transaction from J2EE" Watch "Commiting a transaction from J2EE" New topic

Commiting a transaction from J2EE

Ravi Singh
Ranch Hand

Joined: Aug 02, 2004
Posts: 51
When using JDBC to execute updates in the database, if you use a statement like the following in a J2EE application:


does the commit action actually get executed on the database because I am under the impression that all transactions are managed by the container?

If this is the case, is the commit() method simply ignored?
PNS Subramanian
Ranch Hand

Joined: Jul 13, 2004
Posts: 150
When the transaction setting in the config file (ejb-jar.xml) is "Container", the transactions are indeed managed by the container and as per spec's, commit and rollback statements are not to be used in code.

These are to be used only incase of Bean Managed Transaction, where in the transaction setting in ejb-jar.xml file would be "Bean".

Refer http://java.sun.com/j2ee/1.4/docs/tutorial/doc/index.html in case of further queries.
Ravi Singh
Ranch Hand

Joined: Aug 02, 2004
Posts: 51

I understand the concept of BM and CM transactions but does anyone know what would happen if you placed a commit() statement in a bean which had its transactions managed by the container?

Would an exception be thrown or would the commit simply be ignored?
Have you tried LearnNowOnline? http://www.learnnowonline.com/
subject: Commiting a transaction from J2EE