Hibernate mysql innodb

你说的曾经没有我的故事 提交于 2019-12-22 01:36:13

问题


I wanted to force hibernate to use innodb.

So, i changed the "hibernate.dialect" in order to have innodb, but i can connect to mysql, but when i do some transactions i have the following error:

org.springframework.transaction.TransactionSystemException: Could not commit JPA transaction; nested exception is javax.persistence.RollbackException: Transaction marked as rol lbackOnly at org.springframework.orm.jpa.JpaTransactionManager.doCommit(JpaTransactionManager.java:465) at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:709) at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:678) at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:321) at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:116) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204) at $Proxy46.deleteAsset(Unknown Source)

here is my 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>

Do you have any idea ?


回答1:


Hibernate has no say in whether a table is Inno, MyISAM or another storage engine - that's decided on the MySQL side. There are defaults in the server config, and you can override them when you create tables.

The difference would not have given you the trace - all that happens when you use transactions on a MyISAM table, is you get no transactions. Everything succeeds, but there's no isolation and no roll-backs.

Per @shipmaster, your trace means you have an underlying problem, which is probably not related to your dialect choice. Take a look in the logs, or attach Spring's sources to the project and trace through them.




回答2:


Using the MySQL5InnoDBDialect just tells Hibernate to add "ENGINE=InnoDB" when generating DDL during schema export, nothing more. I'm not sure existing tables will be altered though. So if you have existing tables using MyISAM, you may have to alter them manually.



来源:https://stackoverflow.com/questions/3103506/hibernate-mysql-innodb

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!