Results 1 to 5 of 5

Thread: Transaction problems with Hibernate and MySQL

  1. #1

    Default Transaction problems with Hibernate and MySQL

    Hi, i'm experiencing some transaction problems when using spring's HibernateTemplates.

    Basically, i do this:

    public void addProveedor(IProveedor prov) throws DataAccessException {
    getHibernateTemplate().saveOrUpdate(prov);
    }

    An invocation to this method causes an 'autocommit' behaviour, i mean, prov's data is automatically visible in the DB table.

    I'm using MySQL and the table i use is INNODB type.

    I don't know what i'm doing wrong. When I run the test in a 'standalone' Hibernate fashion (without Spring) i get the expected behaviour, meaninig that i must explicitly call commit to get the data in the database.

    Thanks and sorry for my english

  2. #2
    Join Date
    Aug 2004
    Location
    Montréal, Canada
    Posts
    845

    Default

    juanmanuel32,

    Could you provide the configuration of your DAO, Services, Transaction (from applicationXContext.xml)?
    Omar Irbouh

    Spring Modules Team
    http://irbouh.blogspot.com/

  3. #3

    Default

    Hi,

    i remember having similiar problems and it took me a while to figure out that i had to use a DataSource-wrapper for the mysql connection. I think the problem was that the mysql jdbc driver did not allow to turn off the autocommit feature. (I apended my configuration below)

    Of course you still have to set up a TransactionManager and use it either programmatically or with a TransactionProxyFactoryBean.

    So, here is my code:

    Code:
        <bean id="dataSourceJdbc" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
            <property name="driverClassName">
                <value>com.mysql.jdbc.Driver</value>
            </property>
            <property name="url">
                <value>jdbc&#58;mysql&#58;//127.0.0.1/test</value>
            </property>
            <property name="username">
                <value>root</value>
            </property>
            <property name="password">
                <value></value>
            </property>
            <property name="defaultAutoCommit">
                <value>false</value>
            </property>
        </bean>
    I hope this gives you a hint towards the problem.

    Sebastian

  4. #4

    Default

    Thanks, i will try this and then i'll let you now what happened

  5. #5

    Default

    Hi, i tried with the org.apache.commons.dbcp.BasicDataSource and worwed fine.
    Tanks

Similar Threads

  1. Replies: 6
    Last Post: Jan 11th, 2010, 11:17 PM
  2. CommitException ??
    By vaibhavkhattri in forum Data
    Replies: 2
    Last Post: Aug 11th, 2005, 04:09 AM
  3. Replies: 0
    Last Post: Jun 6th, 2005, 06:22 AM
  4. Newbie. Hibernate + MySQL
    By abstraction in forum Data
    Replies: 6
    Last Post: Oct 24th, 2004, 10:41 PM
  5. Transaction pb Hibernate/MySQL
    By syluser in forum Data
    Replies: 2
    Last Post: Aug 28th, 2004, 02:40 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •