Hibernate Criteria.setLockMode have unexpected behaviour when used in conjunction with MySQL

Description

You expect hibernate to issue a select ... for update when issuing a Criteria of this form:

// This fails
Criteria c = s.createCriteria(SampleEntity.class);
c.setLockMode( LockMode.PESSIMISTIC_WRITE );
SampleEntity e = (SampleEntity) c.uniqueResult();

But the MySQL dialect class simply ignore the lock mode per alias since MySQL does not support a per-table locking strategy. However, in the previous case,
it should issue a for update since we access ALL query tables in update.

Also, since pessimistic lock may be critical for some process synchronization, it should AT LEAST not silently fail.

Attachments

1
  • 15 Apr 2011, 03:05 PM

Activity

Darryl MilesMarch 16, 2012 at 5:05 PM

Confirmed broken in 3.6.9.

Confirmed fixed in 3.6.10.

Both for MySQL usage.

Darryl MilesMarch 16, 2012 at 4:51 PM

I too have found this problem when inspecting the SQL output of show_sql=true

I altered my pom.xml of my application provide to wind back the Hibernate versions and found that this is became broken in 3.5.0-Final and last worked in 3.3.2.GA of hibernate-core. When I wound the version back core=3.3.2.GA, so added annotations=3.3.1.GA and entitymanager=3.3.2.GA and I see "select ... for update" in the show_sql=true output.

I did not test 3.4.x as I did not find it in Maven.

I believe Scott Marlow did some work to deprecate LockMode.UPGRADE and introduce some extra new modes at around this time, so that more fine-grained behavior could be provided. This change set appeared to break support completely.

Duplicate

Details

Assignee

Reporter

Components

Affects versions

Priority

Created April 15, 2011 at 3:05 PM
Updated March 16, 2012 at 5:05 PM
Resolved March 16, 2012 at 5:03 PM

Flag notifications