I am not sure whats the best way to inject Hibernate's session instance to DAO classes using Spring3. I am not using Spring's Hibernate Template support for this so here is the code i have in the DAO class.
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;
}
Below is the code for injecting session in to this method
<bean id="genericSessionFactory" class="HibernateSessionFactory"
factory-method="getSessionfactory" scope="prototype/>
I am not sure if this is the best way to do SessionFactory injection since we don't want to use Spring Template for our project.
So any other suggestion for improvement will be much helpfull.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…