no transaction is in progress


主要: <prop key="hibernate.allow_update_outside_transaction">true</prop>

<?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:context="http://www.springframework.org/schema/context"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xmlns:p="http://www.springframework.org/schema/p" xmlns:jpa="http://www.springframework.org/schema/data/jpa"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
                           http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
                           http://www.springframework.org/schema/context
                           http://www.springframework.org/schema/context/spring-context-4.3.xsd
                           http://www.springframework.org/schema/mvc
                           http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd
                           http://www.springframework.org/schema/aop
                           http://www.springframework.org/schema/aop/spring-aop-4.3.xsd
                           http://www.springframework.org/schema/tx
                           http://www.springframework.org/schema/tx/spring-tx-4.3.xsd
                           http://www.springframework.org/schema/data/jpa
                           http://www.springframework.org/schema/data/jpa/spring-jpa.xsd"
       default-lazy-init="true">
 
     <!--配置數據源-->
    <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
        <property name="driverClass" value="${jdbc.driver}" />  <!--數據庫連接驅動-->
        <property name="jdbcUrl" value="${jdbc.jdbcUrl}" />     <!--數據庫地址-->
        <property name="user" value="${jdbc.user}" />   <!--用戶名-->
        <property name="password" value="${jdbc.password}" />   <!--密碼-->
        <property name="maxPoolSize" value="${jdbc.maxPoolSize}" />      <!--最大連接數-->
        <property name="minPoolSize" value="${jdbc.miniPoolSize}" />       <!--最小連接數-->
        <property name="initialPoolSize" value="${jdbc.initialPoolSize}" />      <!--初始化連接池內的數據庫連接-->
        <property name="maxIdleTime" value="${jdbc.maxIdleTime}" />  <!--最大空閑時間-->
    </bean>
    
 
    <!--配置session工廠-->
    <bean id="sessionFactory" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <property name="packagesToScan" value="com.kintech.model" />
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop> <!--hibernate根據實體自動生成數據庫表-->
                <prop key="hibernate.dialect">${hibernate.dialect}</prop>   <!--指定數據庫方言-->
                <prop key="hibernate.show_sql">${hibernate.show_sql}</prop>     <!--在控制台顯示執行的數據庫操作語句-->
                <prop key="hibernate.format_sql">${hibernate.format_sql}</prop>     <!--在控制台顯示執行的數據哭操作語句(格式)-->
                <prop key="hibernate.cache.use_second_level_cache">${hibernate.cache.use_second_level_cache}</prop>
                <prop key="hibernate.cache.use_query_cache">${hibernate.cache.use_query_cache}</prop>  <!-- 查詢緩存 -->
                <prop key="hibernate.cache.provider_class">${hibernate.cache.provider_class}</prop>
                <prop key="hibernate.cache.region.factory_class">${hibernate.cache.region.factory_class}</prop>
       <!-- 很重要,不然會報:no transaction is in progress 錯誤  -->         
                <prop key="hibernate.allow_update_outside_transaction">true</prop>
            </props>
        </property>
    </bean>
 
</beans>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM