PDA

View Full Version : spring + kodo JDO - no active transaction running



cig
Sep 16th, 2004, 09:38 AM
Hi

I am using Spring with kodo JDO. I am trying to get the programmatic transaction management working. The code I use looks as follows:

protected void doStore(final SPJDeal dealForAddition) {
TransactionTemplate tt = new TransactionTemplate(ptm);
tt.setPropagationBehavior(TransactionDefinition.PR OPAGATION_REQUIRED);
tt.execute(new TransactionCallback() {
public Object doInTransaction(TransactionStatus transStatus) {
return new JdoTemplate(pmf).execute(new JdoCallback() {
public Object doInJdo(PersistenceManager pm) throws JDOException {
dealsHolder.add(dealForAddition);
return null;
}

});
}
});
}


This code (from what I can see) is exactly the same as the code in the Spring test case for JdoTransactionManagerTests#testTransactionCommit() .
However when I run it, I get the following exception:


There is no active transaction running for (0:0-2601#0, 125)
at com.poet.rt.db.JDOBindingSupport.noActiveTransacti on(Unknown Source)
at com.poet.rt.db.LocalPersistenceManager.writeFieldO utsideTransaction(Unknown Source)
at com.poet.rt.db.LocalStateManager.makeDirty(Unknown Source)
at com.poet.rt.db.tracked.TrackedObjectHelper.jdoMake Dirty(Unknown Source)
at com.poet.rt.db.tracked.TrackedArrayList.jdoMakeDir ty(Unknown Source)
at com.poet.rt.db.tracked.TrackedArrayList.preWrite(U nknown Source)
at com.poet.rt.db.tracked.TrackedArrayList.add(Unknow n Source)
at za.co.rmb.spj.deals.domain.DealsHolder.add(DealsHo lder.java:26)
at za.co.rmb.spj.deals.session.JdoDealRepository$2.do InJdo(JdoDealRepository.java:148)
at org.springframework.orm.jdo.JdoTemplate.execute(Jd oTemplate.java:130)
at za.co.rmb.spj.deals.session.JdoDealRepository$1.do InTransaction(JdoDealRepository.java:145)
at org.springframework.transaction.support.Transactio nTemplate.execute(TransactionTemplate.java:114)
at za.co.rmb.spj.deals.session.JdoDealRepository.doSt ore(JdoDealRepository.java:143)
at za.co.rmb.spj.deals.session.JdoDealRepository.stor e(JdoDealRepository.java:136)
at za.co.rmb.spj.deals.session.StoreTask.execute(Stor eTask.java:29)



I would be very gratefull if anybody could help me out.

thanks

Rod Johnson
Sep 16th, 2004, 10:30 AM
What transaction manager are you using?

cig
Sep 17th, 2004, 12:26 AM
The JdoTransactionManager. Below is a snippet from the applicationContext.xml,

<bean id="pmf" class="org.springframework.orm.jdo.LocalPersistenceManage rFactoryBean">
<property name="jdoProperties">
<props>
<prop key="javax.jdo.PersistenceManagerFactoryClass">com.poet.jdo.PersistenceManagerFactories</prop>
<prop key="javax.jdo.option.ConnectionURL">fastobjects://cix/DVBase</prop>

<prop key="javax.jdo.option.Optimistic">true</prop>
<prop key="javax.jdo.option.RetainValues">true</prop>
<prop key="javax.jdo.option.RestoreValues">true</prop>
<prop key="javax.jdo.option.NontransactionalRead">true</prop>
<prop key="javax.jdo.option.NestedTransactionsEnabled">true</prop>

</props>
</property>
</bean>

<bean id="ptm" class="org.springframework.orm.jdo.JdoTransactionManager">
<property name="persistenceManagerFactory">
<ref bean="pmf"/>
</property>
</bean>

cig
Sep 20th, 2004, 02:03 AM
Does anybody have any idea why the Kodo JDO implementation does not seem to pick up the transaction which I'm passing it? I have tried both the declarative and programmatic approaches. Any ideas would be very appreciated.

thanks

Rod Johnson
Sep 20th, 2004, 07:07 AM
In JDO 1.0, JDO-managed persistent objects are not writable outside of the transaction that they were originally loaded with. You need to load "dealsHolder" and modify it within the same transaction.

Juergen

cig
Sep 20th, 2004, 08:41 AM
Hi Juergen

When I explicitly wrap the method doStore(Deal) - which calls DealsHolder.add(Deal) in a transaction, it works fine and that is without first loading DealsHolder first. Not sure if I'm understanding you properly?

Below is what I did:



protected void doStore&#40;final SPJDeal dealForAddition, final Transaction txn&#41; &#123;
txn.begin&#40;&#41;;
dealsHolder.add&#40;dealForAddition&#41;;
txn.commit&#40;&#41;;
&#125;