SSH整合笔记

本文详细介绍了如何使用Spring框架整合Hibernate3,通过配置LocalSessionFactoryBean、HibernateTemplate和HibernateTransactionManager来实现持久层操作。示例代码展示了数据源、映射文件路径及Hibernate属性设置等关键步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Spring 和 Hibernate3的整合
1、org.springframework.orm.hibernate3.LocalSessionFactoryBean
相当于,
SessionFactory mSessionFactory = congfig.getSessionFactory();
例子如下:
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<!--
映射文件所在的路径
-->
<property name="mappingDirectoryLocations">
<list>
<!--
spring容器会去该包及子包下搜索所有的映射文件
-->
<value>classpath:com/itheima12/crm/domain</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
</props>
</property>
</bean>
 
 
2、org.springframework.orm.hibernate3.HibernateTemplate
相当于 Session mSession = mSessionFactory.getSession();
例子:
<bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
<property name="sessionFactory">
<ref bean="sessionFactory"/>
</property>
</bean>
 
3、org.springframework.orm.hibernate3.HibernateTransactionManager
相当于
Transaction transaction = session.beginTransaction();
transaction.commit();
 
 
 
 

转载于:https://www.cnblogs.com/YangBinChina/p/8966676.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值