"SELECT ... FOR UPDATE" does not work for Hibernate and MySQL

We have a system in which we must use pessimistic locking in one object. We use sleep mode, so we use LockMode.UPGRADE. However, it is not blocked.

  • InnoDB Tables
  • We checked that the lock works correctly in the database (5.0.32), so this error http://bugs.mysql.com/bug.php?id=18184 does not seem to be a problem.
  • We checked that the data source contains a parameter autoCommit = false.
  • We verified that SQL sleep (version 3.2) generates, including "FOR UPDATE".

Thanks,

+5
source share
3 answers

- . @Transactional Spring, , ( , , ). Hibernate startTransaction , .

, Spring.

+1

, - Spring. Spring tx.

<tx:annotation-driven transaction-manager="txManager"/>
<bean id="txManager" class="org.springframework.orm.hibernate.HibernateTransactionManager">
  <property name="sessionFactory" ref="sessionFactory" />
</bean>

, autocommit = false, , . " "?

, , , Spring tx , - . , FOR UPDATE SQL. Upstack, / @Transactional. - Spring .

+1

Recently, I had such a problem. We, where we work with 2 tx managers, we had different databases, and the problem was that the transaction used txmanager configured for another database, and because of this, when connecting to the requested database, autocommit mode was not disabled before making a choice to upgrade. Using the correct txmanager, this succeeded. Hope this helps others in the future.

0
source

All Articles