首页 文章

Hibernate mysql innodb

提问于
浏览
1

我想强迫hibernate使用innodb .

所以,我改变了“hibernate.dialect”以便拥有innodb,但我可以连接到mysql,但是当我做一些事务时,我有以下错误:

org.springframework.transaction.TransactionSystemException:无法提交JPA事务;嵌套异常是javax.persistence.RollbackException:org.springframework.orm.jpa.JpaTransactionManager.doCommit(JpaTransactionManager.java:465)org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java)中标记为rol lbackOnly的事务: 709)在org.springframework.transaction.intercts.TransactionInterceptor的org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:321)org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:678) .invoke(TransactionInterceptor.java:116)org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)at $ Proxy46 .deleteAsset(未知来源)

这是我的persistence.xml:

<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
    http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd" version="1.0">
    <persistence-unit name="name" transaction-type="RESOURCE_LOCAL">         
        <provider>org.hibernate.ejb.HibernatePersistence</provider>      
        <properties>
            <property name="hibernate.archive.autodetection" value="class, hbm"/>
            <property name="hibernate.show_sql" value="false"/>
            <property name="hibernate.format_sql" value="true"/>
            <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect"/>                      
            <property name="hibernate.hbm2ddl.auto" value="update"/>    
            <!--        
            <property name="hibernate.c3p0.min_size" value="5"/>
            <property name="hibernate.c3p0.max_size" value="20"/>
            <property name="hibernate.c3p0.timeout" value="300"/>
            <property name="hibernate.c3p0.max_statements" value="50"/>
            <property name="hibernate.c3p0.idle_test_period" value="3000"/>     
            --> 
            <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
            <property name="hibernate.connection.url" value="jdbc:mysql://xxxxxx"/>
            <property name="hibernate.connection.username" value="xxxxx"/>
            <property name="hibernate.connection.password" value="xxxxxx"/>

            <property name="defaultAutoCommit" value="false"/>

            <!-- Connection auto reconnect after long inactivity -->
            <property name="connection.autoReconnect" value="true"/>
            <property name="connection.autoReconnectForPools" value="true"/>
            <property name="connection.is-connection-validation-required" value="true"/>
        </properties>
    </persistence-unit>         
</persistence>

你有什么主意吗 ?

2 回答

  • 2

    使用 MySQL5InnoDBDialect 只是告诉Hibernate在模式导出期间生成DDL时添加 "ENGINE=InnoDB" ,仅此而已 . 我不确定现有的表格会被改变 . 因此,如果您使用MyISAM存在现有表,则可能必须手动更改它们 .

  • 2

    Hibernate对于表是Inno,MyISAM还是其他存储引擎没有发言权 - 这是在MySQL方面决定的 . 服务器配置中有默认值,您可以在创建表时覆盖它们 .

    差异不会给你跟踪 - 当你在MyISAM表上使用事务时发生的一切,你没有得到任何交易 . 一切都成功,但没有隔离,没有回滚 .

    根据@shipmaster,您的跟踪意味着您有潜在的问题,这可能与您的方言选择无关 . 查看日志,或将Spring的源附加到项目中并跟踪它们 .

相关问题