Results 1 to 9 of 9

Thread: Need Help: Transaction is not active - Spring + JPOX JDO

  1. #1
    Join Date
    Aug 2004
    Location
    Hong Kong
    Posts
    18

    Default Need Help: Transaction is not active - Spring + JPOX JDO

    I need help urgently.

    I am using Spring 1.1 + JPOX JDO 1.1 Alpha 2 with the JDOTemplate and Spring JdoTransactionManager.

    I have set the JDO properties

    "javax.jdo.option.NontransactionalRead=true"

    I found no problem in doing read only stuffs, but when i try to make persist an object, I got the following error:

    Code:
    Transaction is not active; nested exception is org.jpox.exceptions.TransactionNotActiveException: Transaction is not active
    org.springframework.orm.jdo.JdoUsageException
    This is my DAO for your reference:

    Code:
        public void insert(Object object) throws DataAccessException
        {
            Container container = (Container) object;
            getJdoTemplate().makePersistent(container);
        }
    THANKS A LOT FOR YOUR HELP!

  2. #2
    Join Date
    Aug 2004
    Posts
    2,715

    Default

    I'm not familiar with JPOX and haven't worked with JDO for a while. However, I would say that you require a transaction to persist an object.
    From your explicit stating of the NontransactionalRead property I deduce that you try to work completely without transactions. I think that won't work.

    You will need to open a transaction (maybe declaring your business method transactional using Spring AOP).

    Hope that helps,
    Andreas

  3. #3
    Join Date
    Aug 2004
    Location
    Hong Kong
    Posts
    18

    Default

    Andreas Senft,

    Thanks for your reply. I want all of the persistence having a transaction.

    I did define the Spring JdoTransactionManager and include it with the TransactionProxyFactoryBean, like the followings:

    Code:
    	
    	<!-- Transaction manager for a single Jdo PersistenceManagerFactory &#40;alternative to JTA&#41; -->
    	<bean id="transactionManager" class="org.springframework.orm.jdo.JdoTransactionManager">
    		<property name="persistenceManagerFactory"><ref local="persistenceManagerFactory"/></property>
    	</bean>
    
    <!-- Transactional proxy for container's primary business object -->
    	<bean id="container" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
    		<property name="transactionManager"><ref local="transactionManager"/></property>
    		<property name="target"><ref bean="containerService"/></property>
    		<property name="transactionAttributes">
    			<props>
    				<prop key="update*">PROPAGATION_REQUIRED</prop>
    				<prop key="insert*">PROPAGATION_REQUIRED</prop>
    				<prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
    			</props>
    		</property>
    	</bean>
    However, if I remove JDO properties "javax.jdo.option.NontransactionalRead=true", I can't even read an object with the same error "Transaction is not active".

    Any other can help?
    Beginner of Spring!

  4. #4
    Join Date
    Aug 2004
    Posts
    2,715

    Default

    Quote Originally Posted by dowchen
    However, if I remove JDO properties "javax.jdo.option.NontransactionalRead=true", I can't even read an object with the same error "Transaction is not active".
    That seems to imply for me that there's no transactional context available. I see no error, though, in the snippets you posted.
    Mabe you can ensure with debugging / examining the spring log files that your method is indeed wrapped correctly and executed within a TransactionInterceptor?

    Regards,
    Andreas

  5. #5
    Join Date
    Aug 2004
    Location
    Hong Kong
    Posts
    18

    Default

    Thanks.

    I did turn on the debug and I saw that both the transaction manager and the transactionProxyFactory could be created in the bean factory successfully.

    However, I didn't find any debug log of indicating the method is wrapperd by the transaction interceptor. But I assume that the TransactionProxyFactoryBean will do the transaction wrapped for me automatically once it is instantiated successfully.

    Anyway, any other input will be much appreciate. Thanks!! [/quote]
    Beginner of Spring!

  6. #6
    Join Date
    Aug 2004
    Location
    Hong Kong
    Posts
    18

    Default

    More information on the exception:

    Testcase: testGetContainerById(com.mtl.motos.esf.persistence .PersistenceContainerJDOTest): Caused an ERROR
    Transaction is not active; nested exception is org.jpox.exceptions.TransactionNotActiveException: Transaction is not active
    org.springframework.orm.jdo.JdoUsageException: Transaction is not active; nested exception is org.jpox.exceptions.TransactionNotActiveException: Transaction is not active
    org.jpox.exceptions.TransactionNotActiveException: Transaction is not active
    at org.jpox.NonmanagedTransaction.getConnection(Nonma nagedTransaction.java:241)
    at org.jpox.NonmanagedTransaction.getConnection(Nonma nagedTransaction.java:202)
    at org.jpox.AbstractPersistenceManager.getConnection( AbstractPersistenceManager.java:343)
    at org.jpox.store.query.JDOQLQuery.performExecute(JDO QLQuery.java:244)
    at org.jpox.store.query.Query.executeWithMap(Query.ja va:741)
    at org.jpox.store.query.Query.executeWithArray(Query. java:727)
    Beginner of Spring!

  7. #7
    Join Date
    Aug 2004
    Posts
    2,715

    Default

    Quote Originally Posted by dowchen
    However, I didn't find any debug log of indicating the method is wrapperd by the transaction interceptor. But I assume that the TransactionProxyFactoryBean will do the transaction wrapped for me automatically once it is instantiated successfully.
    I suspect you should find according log information on debug level.

    Either there should be a message like "Getting transaction for ..."
    or a message
    "Don't need to create transaction for ... : this method isn't transactional"
    where ... specified your method.

    In the former case, a transactional context is provided for the specified method. In the latter case it is not. The log messages are generated from TransactionAspectSupport.


    Regards,
    Andreas

  8. #8
    Join Date
    Aug 2004
    Location
    Hong Kong
    Posts
    18

    Default

    Andreas,

    Thanks for your help.

    I have turned on the debug on the class TransactionAspectSupport, but I didn't find any debug messages returned.

    I also tried not to use JDO but to use JDBC template and DataSourceTransactionManager instead, it run successfully, but it also didn't return any debug messages from the TransactionAspectSupport.

    More information provided to you, here is my application context:

    Code:
    <!-- PMF Bean -->
        <bean id="persistenceManagerFactory"
            class="org.springframework.orm.jdo.LocalPersistenceManagerFactoryBean">
    		<property name="jdoProperties">
    			<props>
                    <prop key="javax.jdo.PersistenceManagerFactoryClass">org.jpox.PersistenceManagerFactoryImpl</prop>
                    <prop key="javax.jdo.option.ConnectionURL">jdbc&#58;oracle&#58;thin&#58;@dave&#58;1521&#58;DOW</prop>
                    <prop key="javax.jdo.option.ConnectionUserName">motos</prop>
                    <prop key="javax.jdo.option.ConnectionPassword">motos</prop>
                    <prop key="javax.jdo.option.ConnectionDriverName">oracle.jdbc.driver.OracleDriver</prop>
                    <prop key="org.jpox.autoCreateSchema">true</prop>
                    <prop key="org.jpox.store.Dictionary.CaseIdentifier">PreserveCase</prop>
    			</props>
    		</property>
        </bean>
    
    <!-- Define DAO Implementation -->
       <!-- ContainerDAO - JDO-->
       <bean id="containerDAO" class="persistence.testcase.dao.impl.jdo.ContainerDAOImpl">
    		<property name="persistenceManagerFactory"><ref local="persistenceManagerFactory"/></property>
    	</bean>
    	
    	<!-- For Service &#40;Delegates&#41; Implementation -->
    	<!-- ContainerService -->
    	<bean id="containerService" class="persistence.testcase.service.impl.ContainerServiceImpl">
    		<property name="containerDAO"><ref local="containerDAO"/></property>
    	</bean>
    	
    	<!-- Transactional proxy for container's primary business object -->
    	<bean id="container" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
    		<property name="transactionManager"><ref local="transactionManager"/></property>
    		<property name="target"><ref bean="containerService"/></property>
    		<property name="transactionAttributes">
    			<props>
    				<prop key="update*">PROPAGATION_REQUIRED</prop>
    				<prop key="insert*">PROPAGATION_REQUIRED</prop>
    				<prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
    			</props>
    		</property>
    	</bean>
    Beginner of Spring!

  9. #9
    Join Date
    Aug 2004
    Location
    Hong Kong
    Posts
    18

    Default

    Andreas,

    Please ignore the previous post. Thanks a lot for your kindly help.

    I found that the transaction is not running before, and now fixed.

    This thread could be closed.

    Thanks again!
    Beginner of Spring!

Similar Threads

  1. Unit testing with JOTM and JtaTransactionManager
    By lalle in forum Architecture
    Replies: 1
    Last Post: Oct 15th, 2005, 09:05 AM
  2. Replies: 14
    Last Post: Feb 21st, 2005, 05:41 PM
  3. Replies: 3
    Last Post: Nov 19th, 2004, 07:16 PM
  4. Replies: 5
    Last Post: Sep 20th, 2004, 08:41 AM
  5. Transaction pb Hibernate/MySQL
    By syluser in forum Data
    Replies: 2
    Last Post: Aug 28th, 2004, 02:40 PM

Posting Permissions

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