Results 1 to 5 of 5

Thread: JdoDaoSupport with Annotation Based Config

  1. #1
    Join Date
    Mar 2010
    Posts
    1

    Default 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. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,625

    Default

    Create a constructor which takes the PersistenceManagerFactory and then set it on the super class. That way it will be injected.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  3. #3

    Default

    Quote 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.

  4. #4
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,625

    Default

    No it doesn't, not if you put an @Autowired in there... I suggest a read of the reference guide....
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  5. #5

    Default

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

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

Posting Permissions

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