休眠MySQL innodb [英] Hibernate mysql innodb

查看:94
本文介绍了休眠MySQL innodb的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想强制hibernate使用innodb。

因此,我改变了hibernate.dialect以便拥有innodb,但是我可以连接到mysql,但是当我做一些交易,我有以下错误:




org.springframework.transaction.TransactionSystemException:无法进行交易JPA;嵌套的例外是javax.persistence.RollbackException:事务标记为ROL
lbackOnly
在org.springframework.orm.jpa.JpaTransactionManager.doCommit(JpaTransactionManager.java:465)
。在org.springframework。 transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:709)
处org.springframework.transaction.interceptor org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:678)
。 TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:321)
在org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:116)
在org.springframework.aop.framework.ReflectiveMethodInvocation.proceed( ReflectiveMethodInvocation.java:171)
在org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAop Proxy.java:204)
at $ Proxy46.deleteAsset(Unknown Source)

这里是我的persistence.xml:

 <?xml version =1.0encoding =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版本= 1.0 >
< persistence-unit name =nametransaction-type =RESOURCE_LOCAL>
< provider> org.hibernate.ejb.HibernatePersistence< / provider>
<属性>
< property name =hibernate.archive.autodetectionvalue =class,hbm/>
< property name =hibernate.show_sqlvalue =false/>
< property name =hibernate.format_sqlvalue =true/>
< property name =hibernate.dialectvalue =org.hibernate.dialect.MySQL5InnoDBDialect/>
< property name =hibernate.hbm2ddl.autovalue =update/>
<! -
< property name =hibernate.c3p0.min_sizevalue =5/>
< property name =hibernate.c3p0.max_sizevalue =20/>
< property name =hibernate.c3p0.timeoutvalue =300/>
< property name =hibernate.c3p0.max_statementsvalue =50/>
< property name =hibernate.c3p0.idle_test_periodvalue =3000/>
- >
< property name =hibernate.connection.driver_classvalue =com.mysql.jdbc.Driver/>
< property name =hibernate.connection.urlvalue =jdbc:mysql:// xxxxxx/>
< property name =hibernate.connection.usernamevalue =xxxxx/>
< property name =hibernate.connection.passwordvalue =xxxxxx/>

< property name =defaultAutoCommitvalue =false/>

<! - 长时间不活动时连接自动重新连接 - >
< property name =connection.autoReconnectvalue =true/>
< property name =connection.autoReconnectForPoolsvalue =true/>
< property name =connection.is-connection-validation-requiredvalue =true/>
< / properties>
< / persistence-unit>
< /余辉>

您有任何想法吗?

解决方案

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



这种差异不会给您带来痕迹 - 您在使用事务时发生的一切在MyISAM表上,你没有得到任何交易。一切都成功了,但没有隔离,也没有回滚。

每个@shipmaster,你的踪迹意味着你有一个潜在的问题,这可能与你的方言选择无关。查看日志,或将Spring的源文件附加到项目中并追踪它们。


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 ?

解决方案

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.

这篇关于休眠MySQL innodb的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆