When the custom DAO implements the Org.springframework.orm.hibernate3.support.HibernateDaoSupport, if DAO is to provide the bean in the form of annotations, The sessionfactory is injected in the form of annotations, and the associated set method in Hibernatedaosupport is final, that is, it cannot be overwritten:
Public final void Setsessionfactory (Sessionfactory sessionfactory) {
if (this.hibernatetemplate = = NULL | | Sessionfactory! = This.hibernateTemplate.getSessionFactory ()) {
this.hibernatetemplate = Createhibernatetemplate (sessionfactory);
}
}
Public final void Sethibernatetemplate (Hibernatetemplate hibernatetemplate) {
this.hibernatetemplate = hibernatetemplate;
}
Workaround:
@Transactional
@Repository ("Baselocationdao") public
class Baselocationdaoimpl extends Hibernatedaosupport Implements locationdao{
private Logger Logger = Loggerfactory.getlogger (baselocationdaoimpl.class);
@Resource public
void Setmysessionfactory (Sessionfactory sessionfactory) {
super.setsessionfactory ( sessionfactory);
}
}
the Sessionfactory implementation class should also be configured as an annotated form:
<bean id= "Sessionfactory" class= "Org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean" >
<property name= "DataSource" ref= "DataSource"/>
<property name= "Packagestoscan" value= " Com.pbn.oss.location "></property>
<property name=" Schemaupdate "value=" true "/>
< Property name= "Hibernateproperties" >
<props>
<prop key= "Hibernate.format_sql" >true</ prop>
<prop key= "Hibernate.show_sql" >true</prop>
<prop key= "Hibernate.dialect" > org.hibernate.dialect.sqlserverdialect</prop>
<prop key= "Hibernate.query.factory_class" > org.hibernate.hql.ast.astquerytranslatorfactory</prop>
</props>
</property>
</bean>