在Spring / Hibernate / MySql中,默认情况下是autocommit是true还是false?

时间:2017-11-08 20:48:41

标签: mysql spring hibernate transactions autocommit

我正在使用Amazon RDS MySql 5.5.37服务器和另一个RDS读取副本,mysql-connector-java-5.1.22-bin.jar,Spring 4.3.8.RELEASE和Hibernate 5.1.5.Final。我有这样的SPring / Hibernate配置

<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    <property name="packagesToScan" value="org.mainco.subco" />
    <property name="jpaVendorAdapter">
        <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"/>
    </property>
    <property name="dataSource" ref="dataSource"/>
    <property name="jpaPropertyMap" ref="jpaPropertyMap" />
</bean>

<util:map id="jpaPropertyMap">
    <entry key="hibernate.show_sql" value="false" />
    <entry key="hibernate.hbm2ddl.auto" value="validate"/>
    <entry key="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect"/>
    <entry key="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.JBossTransactionManagerLookup" />
    <entry key="hibernate.cache.region.factory_class" value="org.hibernate.cache.ehcache.EhCacheRegionFactory"/>
    <entry key="hibernate.cache.provider_class" value="org.hibernate.cache.EhCacheProvider"/>
    <entry key="hibernate.cache.use_second_level_cache" value="${enable.hibernate.second_level.cache}" />
    <entry key="hibernate.cache.use_query_cache" value="${enable.hibernate.query.cache}" />
    <entry key="hibernate.generate_statistics" value="false" />
    <entry key="hibernate.event.merge.entity_copy_observer" value="allow" />
    <entry key="hibernate.enable_lazy_load_no_trans" value="true" />
</util:map>

<bean id="entityManager" class="org.springframework.orm.jpa.support.SharedEntityManagerBean">
    <property name="entityManagerFactory" ref="entityManagerFactory"/>
</bean>

<jee:jndi-lookup jndi-name="java:jboss/datasources/MySqlDS" id="dataSource" expected-type="javax.sql.DataSource"/>

<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
    <property name="entityManagerFactory" ref="entityManagerFactory" />
</bean> 

以下是我在JBoss中设置数据源的方法......

        <datasource jndi-name="java:jboss/datasources/MySqlDS" pool-name="MySqlDS" enabled="true" use-java-context="true">
            <connection-url>jdbc:mysql:replication://cidb-aurora-cluster.cluster-dbserver.us-east-1.rds.amazonaws.com:3306,cidb-aurora-read.dbserver.us-east-1.rds.amazonaws.com:3306/dbsid?failOverReadOnly=true</connection-url>
            <driver>mysql</driver>
            <transaction-isolation>TRANSACTION_READ_COMMITTED</transaction-isolation>
            <pool>
                <min-pool-size>10</min-pool-size>
                <max-pool-size>100</max-pool-size>
                <prefill>true</prefill>
            </pool>
            <security>
                <user-name>username</user-name>
                <password>password</password>
            </security>
            <statement>
                <prepared-statement-cache-size>32</prepared-statement-cache-size>
                <share-prepared-statements>true</share-prepared-statements>
            </statement>
        </datasource>
        <drivers>
            <driver name="mysql" module="com.mysql">
                <driver-class>com.mysql.jdbc.ReplicationDriver</driver-class>
            </driver>
            <driver name="h2" module="com.h2database.h2">
                <xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class>
            </driver>
        </drivers>

在我的Java代码中,我用

标记了我的事务服务方法
org.springframework.transaction.annotation.Transactional

注释。我的问题是,在我没有指定的情况下启用或禁用自动提交?接下来的问题是,应该为autoCommit(true或false)的值是什么?

0 个答案:

没有答案