没有发生Spring + Hibernate连接池连接

时间:2014-02-28 07:35:04

标签: java spring hibernate spring-mvc persistence

我正在尝试在我的Hibernate / Spring webservice中实现连接池,配置如下。

    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
      destroy-method="close">
    <property name="driverClassName" value="${dataSource.driverClassName}" />
    <property name="url" value="${dataSource.url}"/>
    <property name="username" value="${dataSource.username}"/>
    <property name="password" value="${dataSource.password}"/>
<!--
    <property name="timeBetweenEvictionRunsMillis" value="1800000"/>
    <property name="numTestsPerEvictionRun" value="3"/>
    <property name="minEvictableIdleTimeMillis" value="1800000"/>
    <property name="initialSize" value="3"/>
    <property name="maxActive" value="10"/>
    <property name="maxIdle" value="10"/>
    <property name="maxWait" value="5000"/>
    <property name="poolPreparedStatements" value="true"/>
    <property name="maxOpenPreparedStatements" value="100"/>
    <property name="testOnBorrow" value="true"/>
    <property name="testWhileIdle" value="true"/>
    <property name="testOnReturn" value="true"/>
    <property name="validationQuery" value="SELECT 1"/>
-->
</bean>
<!--ADD PERSISTENCE SUPPORT HERE (jpa, hibernate, etc)--> 

<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
    <property name="dataSource" ref="dataSource" />
    <property name="annotatedClasses">
        <list>
            <value>com.limousine.domain.AddressDetails</value>
        </list>
    </property>
    <property name="hibernateProperties">
        <props>
            <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
            <prop key="hibernate.show_sql">true</prop> 
            <!--<prop key="hibernate.hbm2ddl.auto">create</prop>-->
        </props>
    </property>
</bean>

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

但我没有得到连接异常。

1 个答案:

答案 0 :(得分:0)

您正在使用不同版本的hibernate来创建Session Factory(hibernate4)和Transaction Manager(hibernate3)。让它们使用相同的休眠版本。

使用

org.springframework.orm.hibernate4.HibernateTransactionManager

org.springframework.orm.hibernate4.LocalSessionFactoryBean