| I've been trying to reproduce this with no luck. In every case (using H2 at any rate), when I force a lock timeout on find, refresh or lock I get javax.persistence.LockTimeoutException - even before any changes. I'll push this to 5.3 final to give you more time to get a test together. But without a test, I will have to reject this one. BTW, the test I wrote goes like this (swap the specific call you want to test, here it is find):
@Test
@TestForIssue( jiraKey = "HHH-8786" )
public void testLockTimeoutFind() {
verifyCleanData();
inTransaction(
session -> {
final Item item = new Item( "mine" );
session.persist( item );
}
);
try {
inTransaction(
session -> {
session.find( Item.class, 1L, LockModeType.PESSIMISTIC_WRITE );
TransactionUtil2.inTransaction(
sessionFactory(),
secondSession -> {
try {
secondSession.find(
Item.class,
1L,
LockModeType.PESSIMISTIC_WRITE,
Collections.singletonMap( AvailableSettings.JPA_LOCK_TIMEOUT, LockOptions.NO_WAIT )
);
fail( "Expecting a failure" );
}
catch ( LockTimeoutException | PessimisticLockException expected ) {
System.out.println( "here : " + expected );
}
}
);
}
);
}
finally {
inTransaction(
session -> session.createQuery( "delete Item" ).executeUpdate()
);
}
}
In case you needed a template |