春季3之前注入休眠会话的最佳方法 3
我不确定使用Spring3将Hibernate的会话实例注入DAO类的最佳方法是什么。我没有使用Spring的Hibernate Template支持,所以这是我在DAO类中的代码。
public void setSessionFactory(SessionFactory sessionFactory){
this.sessionFactory=sessionFactory;
}
public SessionFactory getSessionFactory(){
log.info("Returning a refrence to the session instance");
if(sessionFactory==null){
log.error("Not able to find any associated session");
throw new RuntimeException("Not able to find any associated session");
}
return sessionFactory;
}
下面是将会话注入此方法的代码
<bean id="genericSessionFactory" class="HibernateSessionFactory"
factory-method="getSessionfactory" scope="prototype/>
我不确定这是否是进行SessionFactory注入的最佳方式,因为我们不想在我们的项目中使用Spring Template。因此,任何其他改进建议都将非常有帮助。