Announcement Announcement Module
Collapse
No announcement yet.
JdoDaoSupport with Annotation Based Config Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • JdoDaoSupport with Annotation Based Config

    I'm trying to extend JdoDaoSupport in a DAO using an Annotation based config and I am running into issues. My DAO is setup like this:

    Code:
    @Repository
    @Transactional
    public class UserDao extends JdoDaoSupport {
    
    	public void persist(Object object) {
    		getJdoTemplate().makePersistent(object);
    	}
    }
    My applicationContext.xml looks like this:

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    	xmlns:context="http://www.springframework.org/schema/context"
    	xmlns:tx="http://www.springframework.org/schema/tx"
    	xmlns:security="http://www.springframework.org/schema/security"
    	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
    				http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd				
    				http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
    				http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.0.xsd">
    	
    	<!-- Scans our classes for annotations which describe our beans and how they're wired together -->
    	<context:component-scan base-package="com.llama.domain" />	
    	
    	<!-- Allows annotation based transactions with @Transactional see UserDao for example. -->
    	<tx:annotation-driven />	
            	
    	<!-- BEGIN JDO Persitence Configuration -->
    	<bean id="persistenceManagerFactory"  class="org.springframework.orm.jdo.LocalPersistenceManagerFactoryBean">
    		<property name="persistenceManagerFactoryName" value="transactions-optional" />
    	</bean>	
    	<bean id="transactionManager" class="org.springframework.orm.jdo.JdoTransactionManager">
    		<property name="persistenceManagerFactory" ref="persistenceManagerFactory" />
    	</bean>
    	<!-- END JDO Persitence Configuration -->
    </beans>
    And I'm getting an exception complaining about how the PersistenceManagerFactory is not set. Here is the exception:

    Code:
    Caused by: java.lang.IllegalArgumentException: persistenceManagerFactory or jdoTemplate is required
    	at org.springframework.orm.jdo.support.JdoDaoSupport.checkDaoConfig(JdoDaoSupport.java:114)
    	at org.springframework.dao.support.DaoSupport.afterPropertiesSet(DaoSupport.java:44)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$5.run(AbstractAutowireCapableBeanFactory.java:1451)
    	at java.security.AccessController.doPrivileged(Native Method)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1449)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1398)
    	... 31 more
    Apparently the setPersistenceManagerFactory method is never called with the annotation based config I am using. Do I have other choices beside just using an xml based config for these DAO classes?

  • #2
    Create a constructor which takes the PersistenceManagerFactory and then set it on the super class. That way it will be injected.

    Comment


    • #3
      Originally posted by Marten Deinum View Post
      Create a constructor which takes the PersistenceManagerFactory and then set it on the super class. That way it will be injected.
      That doesn't work. Spring demands a ctor with no parameters for @Repository.

      Comment


      • #4
        No it doesn't, not if you put an @Autowired in there... I suggest a read of the reference guide....

        Comment


        • #5
          That wasn't in your original post. Here's how it can be done:

          Code:
              @Autowired
              public UserDatoDao(PersistenceManagerFactory pmf)
              {
          	setPersistenceManagerFactory(pmf);
              }

          Comment

          Working...
          X