|
Requesting to re-open this issue since the fix breaks use without aliases. Tested with Hibernate 5.0.0.Final, PostgreSQL 9.4.4 and dialect PostgreSQL94Dialect, queries created through JPA and then unwrapped.
Sample query:
session.createQuery("select t.id from Token t where t.validUntil < :valid order by t.id")
.setParameter("valid", Instant.now(), Constants.TIMESTAMP_TYPE)
.setLockMode("this", LockMode.PESSIMISTIC_WRITE)
.list()
When calling query.setLockMode("this",LockMode.PESSIMISTIC_WRITE) the alias on the LockOptions is correctly set. When QueryLoader.applyLocks is called the LockOptions get copied but the sqlAliasByEntityAlias is empty so no aliases are set on the copied LockOptions. Later on ForUpdateFragement gets created with the copied LockOptions that have no aliases, therefore ForUpdateFragment.aliases is empty and when dialect.getForUpdateString( aliases.toString(), lockOptions ) gets called in #toFragmentString() the empty String is passed to #getForUpdateString(String,LockOptions).
I think the error could be in one of two places.
-
when the LockOptions gets copied
-
in ForUpdateFragment
If the correct way to patch this is in ForUpdateFragment: The patched PostgreSQL81Dialect doesn't distinguish between empty and non-empty aliases. Therefore ForUpdateFragment#toFragmentString() needs to be changed to account for empty aliases even though lockOptions != null.
|