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();