Announcement Announcement Module
Collapse
No announcement yet.
Need Help: Transaction is not active - Spring + JPOX JDO Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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

    Comment


    • #3
      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?

      Comment


      • #4
        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

        Comment


        • #5
          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]

          Comment


          • #6
            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)

            Comment


            • #7
              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

              Comment


              • #8
                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>

                Comment


                • #9
                  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!

                  Comment

                  Working...
                  X