Announcement Announcement Module
Collapse
No announcement yet.
Transaction problems with Hibernate and MySQL Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    juanmanuel32,

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

    Comment


    • #3
      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

      Comment


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

        Comment


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

          Comment

          Working...
          X