| Similar to the issue HHH-5654 Closed , which had been fixed in PostgreSql81Dialect, when lock mode was specified with an alias, the generated SQL for Oracle database is not using the alias at all. According to Oracle's documentation of for-update clause, the syntax allows user to specify "table.column" in order to lock the select rows only for a particular table or view in a join.
session.createQuery("from DomainName d left join fetch d.tld where d.name = :dnsName", DomainName.class)
.setLockMode("d", LockMode.PESSIMISTIC_WRITE)
.setParameter("dnsName", domainName.getValue()));
We found out that Hibernate's Oracle dialects did not provide its own implementation of the method String getForUpdateString(String aliases, LockOptions lockOptions), hence it always falls back to the default implementation in org.hibernate.dialect.Dialect (see code below):
public String getForUpdateString(String aliases, LockOptions lockOptions) {
LockMode lockMode = lockOptions.getLockMode();
final Iterator<Map.Entry<String, LockMode>> itr = lockOptions.getAliasLockIterator();
while ( itr.hasNext() ) {
final Map.Entry<String, LockMode>entry = itr.next();
final LockMode lm = entry.getValue();
if ( lm.greaterThan( lockMode ) ) {
lockMode = lm;
}
}
lockOptions.setLockMode( lockMode );
return getForUpdateString( lockOptions ); }
|