按照网上方法,什么设置为FlushMode.AUTO,read-only="false"都没用,吐槽一下,这个hibernate自从4.0开始真的是越来越难用了,作者不知道在想什么,一个配置玩了我一个晚上,hibernate3.2我都用的很顺手
applicationcontext.xml配置:
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
        <!-- <property name="dataSource" ref="dataSource" /> -->
        <property name="configLocation" >
            <value>classpath:hibernate.cfg.xml</value>
        </property>
         
</bean>

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

<!-- 配置事务传播特性 -->
<tx:advice id="transactionAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="save*" read-only="false" rollback-for="Execption" propagation="REQUIRED"/>
<tx:method name="add*" read-only="false" rollback-for="Execption" propagation="REQUIRED"/>
<tx:method name="insert*" read-only="false" rollback-for="Execption" propagation="REQUIRED"/>
<tx:method name="main*" read-only="false" rollback-for="Execption" propagation="REQUIRED"/>
<tx:method name="*" read-only="false" rollback-for="Execption" propagation="REQUIRED"/>
</tx:attributes>
</tx:advice>

<!-- 配置参与事务的类 -->
<aop:config>
<aop:pointcut expression="execution(* dsm.login.test.*.*(..))"
id="transactionPoint" />
<aop:advisor advice-ref="transactionAdvice" pointcut-ref="transactionPoint" />
</aop:config>

<!--  hibernateTemplate配置 -->
<bean id="hibernateTemplate" class="org.springframework.orm.hibernate4.HibernateTemplate">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>

<!--创建JdbcTemplate对象,注入连接池dataSource-->
    <!-- <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
        <property name="dataSource" ref="dataSource"></property>
    </bean> -->

</beans>
hibernate.cfg.xml配置:
<session-factory >        <property name="connection.driver_class">org.mariadb.jdbc.Driver</property>
        <property name="connection.url">jdbc:mariadb://localhost:3306/dsm</property>
        <property name="connection.username">root</property>
        <property name="connection.password">3836128</property>
        <property name="dialect">org.hibernate.dialect.MySQL5InnoDBDialect</property>
        <property name="show_sql">true</property>
        <property name="format_sql">true</property>
        <property name="hibernate.jdbc.batch_size">20</property> 
        <property name="hibernate.jdbc.fetch_size">50</property> 
        
        <!-- 数据库连接池的使用 -->
        <!-- 选择使用C3P0连接池 -->
        <property name="hibernate.connection.provider_class">org.hibernate.c3p0.internal.C3P0ConnectionProvider</property>
        <!-- 连接池中最小连接数 -->
        <property name="hibernate.c3p0.min_size">20</property>
        <!-- 连接池中最大连接数 -->
        <property name="hibernate.c3p0.max_size">100</property>
        <!-- 设定数据库连接超时时间,以秒为单位。如果连接池中某个数据库连接处于空闲状态且超过timeout秒时,就会从连接池中移除-->
        <property name="hibernate.c3p0.timeout">200</property>
        <!-- 最大的PreparedStatement的数量 --> 
<property name="hibernate.c3p0.max_statements">150</property>
<!-- 当连接池里面的连接用完的时候,C3P0一下获取的新的连接数 -->
<property name="hibernate.c3p0.acquire_increment">20</property>
<!-- <property name="hibernate.connection.autocommit">false</property> -->
<!-- 不使用默认jdbc -->
<property name="hibernate.temp.use_jdbc_metadata_defaults">false</property>         <!-- <mapping resource="dsm/login/user/Employee.hbm.xml"/> --> 
        <!-- <mapping class="dsm.login.user.Employee"/>  -->
        
    </session-factory>代码:包结构: