Results 1 to 2 of 2

Thread: Spring 2.5 HibernateDaoSupport/Annotations best practices

  1. #1
    Join Date
    May 2006
    Posts
    11

    Default Spring 2.5 HibernateDaoSupport/Annotations best practices

    I used to have a getter/setter for sessionFactory in the base class my DAOs extended from (which extended from HibernateDaoSupport). To get the same thing to work with annotations and Spring 2.5 I had to use constructor injection. like:

    Code:
    package whitney.repository.dao;
    
    import org.hibernate.SessionFactory;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
    import org.springframework.stereotype.Repository;
    
    import whitney.entity.Entry;
    
    @Repository
    public class EntryDao extends HibernateDaoSupport{
    	
    	@Autowired
    	public EntryDao(SessionFactory sessionFactory){
    		super.setSessionFactory(sessionFactory);
    	}
    	
    	public void save(Entry entry){
    		this.getHibernateTemplate().save(entry);
    	}	
    }
    This isn't really a problem, but I used to like making some of my classes autowired by default, like:

    Code:
    <bean id="blah" class="foo.Blah" autowired="byName"/>
    I guess this just isn't possible any more if I want to use the new spring 2.5 annotations?

  2. #2
    Join Date
    Apr 2005
    Posts
    11

    Default

    Check the @Resource annotation it can autowired by name. Notice you need jdk-1.6 cause the @Resource annotation is present in jdk-1.6.

    Link to the springframework documentation:

    http://static.springframework.org/sp...rce-annotation

Posting Permissions

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