spring 2.5+hibernate 3.0整合

本文介绍如何在Spring框架中整合Hibernate3.0,包括配置文件的详细设置,如事务管理、数据源配置、SessionFactory初始化等关键步骤。

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

hibernate 3.0配置文件和spring 2.5.6配置文件都放在src目录下,
spring配置文件如下配置


<tx:annotation-driven transaction-manager="txManager"/>

<bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>


<bean id="hbmlist" class="java.util.ArrayList">
<constructor-arg>
<list>
<value>/conf/model/User.hbm.xml</value>
<value>/conf/model/DictItem.hbm.xml</value>
</list>
</constructor-arg>
</bean>

<bean id="hibernateProperties"
class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<property name="properties">
<props>
<prop key="hibernate.dialect">${mysql.hibernate.dialect}</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.format_sql">true</prop>
<!--
<prop key="hibernate.cache.use_second_level_cache">true</prop>
<prop key="hibernate.cache.use_query_cache">true</prop>
<prop key="hibernate.cache.region.factory_class">net.sf.ehcache.hibernate.EhCacheRegionFactory</prop>
-->
<!--
<prop key="hibernate.transaction.factory_class">org.hibernate.transaction.JTATransactionFactory</prop>
<prop key="hibernate.transaction.manager_lookup_class">com.atomikos.icatch.jta.hibernate3.TransactionManagerLookup</prop>
<prop key="hibernate.query.substitutions" >true</prop>
<prop key="hibernate.query.factory_class">org.hibernate.hql.classic.ClassicQueryTranslatorFactory</prop>
-->
<!-- <prop key="hibernate.hbm2ddl.auto">update</prop> -->
<!-- <prop key="hibernate.cache.use_query_cache">true</prop>-->
<!-- <prop key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</prop>-->
</props>
</property>
</bean>


<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:/conf/dbusers.properties</value>
</list>
</property>
</bean>

<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" >
<value>${mysql.driverName}</value>
</property>
<property name="url">
<value>${mysql.url}</value>
</property>
<property name="username">
<value>${mysql.user}</value>
</property>
<property name="password">
<value>${mysql.password}</value>
</property>
</bean>



<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="mappingResources" ref="hbmlist"/>
<property name="hibernateProperties" ref="hibernateProperties"/>
</bean>


2、所有dao类都继承 org.springframework.orm.hibernate3.support.HibernateDaoSupport
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值