[jboss-user] [JCA/JBoss] - Re: XA Connection error

weston.price@jboss.com do-not-reply at jboss.com
Wed Sep 6 17:31:21 EDT 2006


Let me see if I can explain this a bit more clearly: 

In your case, it does not appear that you are leveraging CMT or using the UserTransaction object from JNDI to start/commit a transaction. If that is indeed the case, you are going to want to use the 

<no-tx-datasource>

Using this requires you to do the setAutoCommit(false) and commit explicitly, otherwise, ever statement issued will be done in the context of a seperate JDBC transaction. In that scenario your *code* was correct, but the type of datasource was wrong. 

If you wanted to get away from managing your own transactions and leverage J2EE transaction management there are generally two approaches: 

1) Use EJB (or some other declaractive transaction technology)

2) Use the UserTransaction object from JNDI to start/commit/rollback a transaction. 

Typically #2 is used with straight Web (non-EJB) applications and looks something like this: 

Servlet or JSP


  | Context ic = new InitialContext();
  | UserTransaction ut =
  | 	(UserTransaction) ic.lookup("java:comp/UserTransaction");
  | ut.begin();
  | // access resources transactionally here
  | ut.commit();
  | 
  | 

What we are talking about is transaction 'boundaries'. Technologies like EJB(2/3) allow you to declare transactions on method boundaries. Servlets/JSP do not, but allow access to the UserTransaction object (as can be seen above).

Note, either approach is neither 'right' or 'wrong', it's simply a matter of what your application requires. However, since you are running in a J2EE environment, CMT or UserTransaction delinated boundaries are typcially the preferred approach. 




View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3969890#3969890

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3969890



More information about the jboss-user mailing list