我想强制hibernate使用innodb。
因此,为了拥有innodb,我更改了“hibernate.dialect”,但是我可以连接到mysql,但是当我执行某些事务时,出现以下错误:
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)
这是我的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>
你有什么主意吗 ?
Hibernate对于表是Inno,MyISAM还是其他存储引擎没有发言权-这是在MySQL方面决定的。服务器配置中有默认值,您可以在创建表时覆盖它们。
差异不会给您带来跟踪-当您在MyISAM表上使用事务时,所有操作都会发生,因为您没有事务。一切都成功了,但是没有隔离,没有回滚。
根据@shipmaster,您的跟踪记录表明您有潜在的问题,这可能与您选择的方言无关。查看日志,或将Spring的源代码附加到项目中并进行跟踪。