Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Commiting a transaction from J2EE

 
Ravi Singh
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When using JDBC to execute updates in the database, if you use a statement like the following in a J2EE application:

con.commit();

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
Posts: 150
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks.

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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic