I'm basically trying to do what I've done with the Hibernate, Spring JDBC and iBATIS SupportDaos. I usually just declare a DAO, set it's dataSource, sessionFactory, persistenceManager or whatever it may be and then run with it. When I test these DAOs, there is no transactions declared on them.
I tried to do the following with JDO:
Code:
<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.ConnectionDriverName">com.mysql.jdbc.Driver</prop>
<prop key="javax.jdo.option.ConnectionUserName">root</prop>
<prop key="javax.jdo.option.ConnectionPassword"></prop>
<prop key="javax.jdo.option.ConnectionURL">jdbc:mysql://localhost/appfuse</prop>
<prop key="org.jpox.autoCreateSchema">true</prop>
<prop key="org.jpox.validateTables">false</prop>
<prop key="org.jpox.validationConstraints">false</prop>
</props>
</property>
</bean>
<bean id="transactionManager" class="org.springframework.orm.jdo.JdoTransactionManager">
<property name="persistenceManagerFactory"><ref bean="persistenceManagerFactory"/></property>
</bean>
<bean id="userDAO" class="org.appfuse.dao.jdo.UserDAOJdo">
<property name="persistenceManagerFactory"><ref bean="persistenceManagerFactory"/></property>
</bean>
But when I run my simple DAOTest, I get:
Code:
[junit] Testcase: testGetUsers(org.appfuse.dao.UserDAOTest): Caused an ERROR
[junit] Transaction is not active; nested exception is org.jpox.exceptions.TransactionNotActiveE
xception: Transaction is not active
[junit] org.springframework.orm.jdo.JdoUsageException: Transaction is not active; nested excepti
on is org.jpox.exceptions.TransactionNotActiveException: Transaction is not active
[junit] org.jpox.exceptions.TransactionNotActiveException: Transaction is not active
[junit] at org.jpox.AbstractPersistenceManager.assertActiveTransaction(AbstractPersistenceMa
nager.java:334)
[junit] at org.jpox.AbstractPersistenceManager.makePersistent(AbstractPersistenceManager.jav
a:797)
[junit] at org.springframework.orm.jdo.JdoTemplate$7.doInJdo(JdoTemplate.java:217)
[junit] at org.springframework.orm.jdo.JdoTemplate.execute(JdoTemplate.java:136)
[junit] at org.springframework.orm.jdo.JdoTemplate.makePersistent(JdoTemplate.java:215)
[junit] at org.appfuse.dao.jdo.UserDAOJdo.saveUser(UserDAOJdo.java:26)
[junit] at org.appfuse.dao.UserDAOTest.testGetUsers(UserDAOTest.java:30)
[junit] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[junit] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
[junit] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java
:25)