views:

43

answers:

2

Hi!

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  A: 

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.

Weird, because all my tables are now in InnoDB. ( updated manually)And all work well when i use dialect MySQLDialect instead of MySQL5InnoDBDialect. ( but new table will not be created in InnoDB by default ).
RoD
+1  A: 

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.

Pascal Thivent
Indeed, that's what i wanted, creating by default table with "ENGINE=InnoDB".And for tables previously created in MyISAM, i did a stored procedure that migrate table MyISAM into InnoDB.But, i've the problem when i use MySQL5InnoDBDialect instead of MySQLDialect
RoD