Announcement Announcement Module
Collapse
No announcement yet.
Spring 2.5 HibernateDaoSupport/Annotations best practices Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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

    Comment

    Working...
    X