Results 1 to 3 of 3

Thread: Spring and JtaTransactionManager with POJO's

  1. #1
    Join Date
    Sep 2004
    Posts
    3

    Default Spring and JtaTransactionManager with POJO's

    Hi

    I am new to spring and had a basic query regarding spring jta transaction manager.

    below mentioned is a snippet from the reference documentation

    ------------------------------------------------------------
    If we use JTA, as in the dataAccessContext-jta.xml file from the same sample application, we need to use a container DataSource, obtained via JNDI, and a JtaTransactionManager implementation. The JtaTransactionManager doesn't need to know about the DataSource, or any other specific resources, as it will use the container's global transaction management.

    <bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryB ean">
    <property name="jndiName"><value>jdbc/jpetstore</value></property>
    </bean>

    <bean id="transactionManager"
    class="org.springframework.transaction.jta.JtaTran sactionManager"/>

    -----------------------------------------------------------------------

    what do u mean by the statement - "JtaTransactionManager doesn't need to know about the DataSource, or any other specific resources, as it will use the container's global transaction management." --

    does it mean that if we specify the transaction manager as JtaTransactionManager , then it will use the application servers transaction management features ? if that is the case then if i declaritively mark my methods in POJO's using the spring declarative transaction management features and deploy the entire app in a application server , then automatically spring will take advantage of the transaction manager features of the app server and have the app server abide by the declarative features mentioned by spring for the POJO's ?

    Moreover if the JtaTransactionManager does not need to know about the data soource then why have we declared bean id - dataSource ? what is its purpose ?

    Basically I wanted to get a clear understanding of how does spring actually provide transaction management feautures to POJO's by using the JtaTransactionManager .

    Can anyone please explain in simple terms. I have used EJB's in a transactional environment but am not able to figure out what magic happens if I apply the same declarative features to my POJO's.

    Thanks

    Keith

  2. #2
    Join Date
    Aug 2004
    Location
    Melbourne, Australia
    Posts
    1,104

    Default

    Re: what do u mean by the statement - "JtaTransactionManager doesn't need to know about the DataSource, or any other specific resources, as it will use the container's global transaction management." --

    For a single datasource, you can use the datasource's transaction manager.
    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSou rceTransactionManager">
    <property name="dataSource"><ref local="dataSource"/></property>
    </bean>

    For multiple transactional resources, you just use JTA transaction management, not the individual resource's transaction manager.

    Re: does it mean that if we specify the transaction manager as JtaTransactionManager , then it will use the application servers transaction management features ?

    Yes

    Re: if that is the case then if i declaritively mark my methods in POJO's using the spring declarative transaction management features and deploy the entire app in a application server , then automatically spring will take advantage of the transaction manager features of the app server and have the app server abide by the declarative features mentioned by spring for the POJO's ?

    Yes

    Moreover if the JtaTransactionManager does not need to know about the data soource then why have we declared bean id - dataSource ? what is its purpose ?

    It is not needed for transational reasons but for IoC. If bean "orderDao" needs a datasource, you inject it:
    <bean id="orderDao" class="org.springframework.samples.jpetstore.dao.i batis.SqlMapOrderDao">
    <property name="dataSource"><ref local="orderDataSource"/></property>
    ...
    </bean>

    Re: Basically I wanted to get a clear understanding of how does spring actually provide transaction management feautures to POJO's by using the JtaTransactionManager ... what magic happens...

    Straight from the EJB spec "The Container must make the javax.transaction.UserTransaction interface available to the enterprise bean’s business method or onMessage method via the javax.ejb.EJBContext interface and under the environment entry java:comp/UserTransaction." Spring does the JNDI lookup and uses this transaction manager. Take a look at API docs and source for JtaTransactionManager. It's in the distro.

  3. #3
    Join Date
    Jul 2009
    Posts
    27

    Default Using JTA transaction Manager in TOMCAT

    Hello,

    I want to use JtaTransactionManager using TomCat server only.

    I am using below piece of code in appcontext.xml.

    Code:
    <tx:annotation-driven transaction-manager="txManager" />
    
    	<jee:jndi-lookup id="dataSource" jndi-name="jdbc/myDbOracle" />
    
    
    	<bean id="txManager"
    		class="org.springframework.transaction.jta.JtaTransactionManager">
    		<property name="userTransactionName">
    			<value>UserTransaction</value>
    		</property>
    		<property name="transactionManagerName" value="java:comp/UserTransaction" />
    	</bean>
    I am getting an exception like:
    Code:
    Caused by: javax.naming.NameNotFoundException: Name TransactionManager is not bound in this Context
    	at org.apache.naming.NamingContext.lookup(NamingContext.java:770)
    	at org.apache.naming.NamingContext.lookup(NamingContext.java:153)
    	at org.apache.naming.SelectorContext.lookup(SelectorContext.java:137)
    	at javax.naming.InitialContext.lookup(InitialContext.java:392)
    	at org.springframework.jndi.JndiTemplate$1.doInContext(JndiTemplate.java:155)
    	at org.springframework.jndi.JndiTemplate.execute(JndiTemplate.java:88)
    	at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:153)
    	at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:178)
    	at org.springframework.jndi.JndiLocatorSupport.lookup(JndiLocatorSupport.java:104)
    	at org.springframework.jndi.JndiObjectLocator.lookup(JndiObjectLocator.java:105)
    	at org.springframework.jndi.JndiObjectFactoryBean.lookupWithFallback(JndiObjectFactoryBean.java:200)
    	at org.springframework.jndi.JndiObjectFactoryBean.afterPropertiesSet(JndiObjectFactoryBean.java:186)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1369)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1335)
    	... 54 more
    Mar 15, 2010 1:18:31 PM org.apache.catalina.core.StandardContext loadOnStartup
    SEVERE: Servlet /STEST threw load() exception
    Can any one tell where i am going wrong?

    Am i supposed to use an App server like Jboss or weblogic to perform a Jta managed transacton which is not possible in TomCat?

    If it is possible with tomcat, can any one rectify me where i am going wrong?

    Thanks a lot for your help.

    Manoj

Similar Threads

  1. Spring MVC Web Framework versus Struts
    By biguniverse in forum Web Flow
    Replies: 27
    Last Post: Aug 29th, 2012, 03:57 AM
  2. Replies: 5
    Last Post: Aug 9th, 2008, 05:30 AM
  3. A Spring Class Loader?
    By azzoti in forum Architecture
    Replies: 8
    Last Post: May 7th, 2005, 04:02 AM
  4. Replies: 14
    Last Post: Feb 21st, 2005, 05:41 PM
  5. Replies: 2
    Last Post: Jan 21st, 2005, 04:17 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •