[jboss-user] [JCA/JBoss] - Re: XA Connection error
bocio
do-not-reply at jboss.com
Mon Nov 20 10:32:11 EST 2006
"weston.price at jboss.com" wrote : 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.
|
|
|
One of the best post on the topic.
Why don't you add this post on the wiki?
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3987314#3987314
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3987314
More information about the jboss-user
mailing list