如题,
知道的讲讲下,
谢谢了、
知道的讲讲下,
谢谢了、
解决方案 »
- java 获取类方法 /**...*/ 格式下的注释内容
- SSH实现联级
- 200分(我只能发100分的帖子)求答案 每日构建
- rich:calendar控件如何验证空
- 在jsp页中怎么实现禁止后退的功能
- JMS的连接问题(linux) 在线等
- 今天刚学struts,找不到org.apache.…的包
- EJB的server和client分别在两个不同的机器上,用RMI访问速度其慢,怎么提高效率阿??
- 各位一定要帮我:Resin服务器的问题!
- 谁能介绍一些关于jbuilder,ejb开发的好书或好的站点。
- 关于hibernate one-to-many配了 fetch=join 的时候,产生重复记录
- 收集spring和hibernate的面试题
this.hibernateTemplate = new HibernateTemplate(sessionFactory);
}
/*用hiberanteTemplate进行操作*/
}配置文件要配置<beans> <bean id="myProductDao" class="product.ProductDaoImpl">
//可以省去property如果采用autowire:byName或byType
<property name="sessionFactory" ref="mySessionFactory"/>
</bean></beans>2:daoimpl mextends HibernateDaoSupport
public class ProductDaoImpl extends HibernateDaoSupport implements ProductDao { public Collection loadProductsByCategory(String category) throws DataAccessException {
return this.getHibernateTemplate().find(
"from test.Product product where product.category=?", category);
}
}
配置因为HibernateDaoSupport 封装了sessionFactory所以配置和上面是一样的。
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"
lazy-init="false">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</prop>
</props>
</property> <property name="mappingLocations"
value="classpath:*.hbm.xml" /> </bean>
你的Dao要么继承自HibernateDaoSupport.或者你单独将这个sessionFactory注入到HibernateTemplate中,再将HibernateTemplate注入到你的dao中
<bean id="myProductDao" class="product.ProductDaoImpl">
//可以省去property如果采用autowire:byName或byType
<property name="sessionFactory" ref="mySessionFactory"/>
</bean>
这个sessionFactory每次都需要声明注入到这个dao里,
我需要的是只写
<bean id="myProductDao" class="product.ProductDaoImpl">
</bean>
这个就行了,不去声明注入sessionFactory,
想由spring自动完成注入。