PDA

View Full Version : Container-managed transactions without JNDI?



jmakeig
Sep 7th, 2004, 04:08 PM
Page 233 of "J2EE Development without EJB" says

For resources to participate in container transactions, they must be configured appropriately. For JDBC, it's necessary to set up a JNDI DataSource via the ... javax.sql.XADataSource ...
Is this a hard and fast requirement? Is it possible to get container-managed JDBC transactions without reliance on JNDI?

- Justin Makeig

Rod Johnson
Sep 7th, 2004, 05:29 PM
Is it possible to get container-managed JDBC transactions without reliance on JNDI?

No, if you mean transactions managed by an EJB container. To do this you need a JNDI DataSource in all cases. If you use CMT, you don't need a JNDI lookup for tx mgt, but if you use BMT you need to look up the UserTransaction object in JNDI. (Plus you'll JNDI to locate your EJB to invoke it.)

With Spring you can have Spring-managed JDBC transactions without JNDI using DataSourceTransactionManager. If you use JtaTransactionManager there's a JNDI lookup under the covers, although you don't need to write that code.

If you're in an app server environment, a JNDI DataSource is probably a good idea. If you're in a pure web container, using a non-JNDI DataSource often makes sense.

Rgds
Rod