在SSH整合过程中:org/hibernate/engine/spi/SharedSessionContractImplementor

本文详细介绍了如何解决Spring3与Hibernate5的版本冲突问题,通过使用正确的Spring3与Hibernate4版本组合,并配置c3p0连接池,实现数据库操作的无缝衔接。文章提供了具体的配置示例,包括配置文件的XML代码片段,涵盖了连接池设置、Hibernate属性配置、映射文件定义、业务层及DAO层配置等关键步骤。

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

我之前是用的Spring3+Hibernate5 发现有冲突。

研究后,正确的版本关系是Spring3+Hibernate4

在网上下载Hibernate4的包替换Hibernate5的包 加入lib

然后在配置连接池的时候,需要下载c3p0的jar包 

还需要下载org.springframework.orm......jar包


我的配置

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:p="http://www.springframework.org/schema/p"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns:tx="http://www.springframework.org/schema/tx" xmlns:util="http://www.springframework.org/schema/util"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
	    http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
	    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">


    <!--加载properties文件-->
    <context:property-placeholder location="WEB-INF/connectFactor.properties"/>

    <!--配置连接池-->
    <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
        <property name="driverClass" value="${jdbc.driver}"/>
        <property name="jdbcUrl" value="${jdbc.url}"/>
        <property name="user" value="${jdbc.user}"/>
        <property name="password" value="${jdbc.password}"/>
     </bean>

    <!--配置Hibernate的相关属性-->
    <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
        <!--配置连接池-->
        <property name="dataSource" ref="dataSource"/>
        <!--配置Hibernate属性-->
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
                <prop key="show_sql">true</prop>
                <prop key="hibernate.hbm2ddl.auto">update</prop>
            </props>
        </property>
        <!--配置mapping文件-->
        <property name="mappingResources">
            <list>
                <value>com/mooc/ssh/domain/Product.hbm.xml</value>
            </list>
        </property>
    </bean>



    <!--配置一个Action-->

    <bean id="productAction" class="com.mooc.ssh.action.ProductAction" scope="prototype">
        <property name="productService" ref="productService"></property>
    </bean>


    <!--配置业务层的类-->
    <bean id="productService" class="com.mooc.ssh.service.ProductService">
        <property name="productDao" ref="productDao"/>
     </bean>
    <!--配置一个DAO的类-->
    <bean id="productDao" class="com.mooc.ssh.dao.ProductDao">
        <property name="sessionFactory" ref="sessionFactory"/>
    </bean>

    <!--配置事务管理器-->
    <bean id="txManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
        <property name="sessionFactory" ref="sessionFactory"/>
    </bean>

    <!--开启注解事务-->

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



</beans>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值