Hibernate DAO Support, HibernateDAOSupport afterPropertiesSet().
This method is called in support of HibernateDAO, and while sessionFactory is null, it causes this error. In your custom class, you can explicitly set this property and then call the same method of the parent class (i.e. the HibernateDAOSupport addProperties () method)
package com.techcielo.spring4.hibernate.template;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.stereotype.Component;
@Component("hibernateTemplate")
public class Hibernate4CustomTemplate extends HibernateTemplate{
@Autowired(required=true)
private SessionFactory sessionFactory;
public void setSessionFactory(SessionFactory sessionFactory) {
System.out.println("Setting SessionFactory");
this.sessionFactory = sessionFactory;
super.setSessionFactory(sessionFactory);
}
@Override
public void afterPropertiesSet() {
System.out.println("Checking if properties set..."+this.sessionFactory);
setSessionFactory(sessionFactory);
super.afterPropertiesSet();
}
}
Below is an example sample !
source
share