Good day.
We have a WARN in the logs “HHH000444: Encountered request for locking however dialect reports that database prefers locking to be done in a separate select (follow-on locking); results will be locked after initial query executes”.
What problems can this cause in our case?
How can we remove this warning or solve it?
Not sure what the @Lock and @Query annotations are doing under the hood, but the warning is pretty self-explanatory: in the first case, the associated collection entities are being fetched eagerly and a pessimistic-write lock is requested - Hibernate is trying to apply the lock, and if the Dialect reports it should use follow-on locking instead we produce that warning.
If you only need to lock the entity owning the association, but not the child entities, than avoid the left-join in the query is your best bet. You can then fetch the association lazily when needed.
And is the blocking actually imposed or not in my case? I don’t see that there are special “select” for locking in the logs as in the example in your link.
I do have lock queries running on both tables as your link says.
Am I right in thinking that the biggest issue here is the possibility of another session changing the data between the time I get the data and the lock?
PESSIMISTIC_WRITE locks prevent this, as you can read here, so it shouldn’t be a concern.
The warning is issued because you’re requesting the lock in a join-fetch query, so the locking will only occur in the Hibernate session after the initial query is executed.
HHH000444: Encountered request for locking however dialect reports that database prefers locking to be done in a separate select (follow-on locking); results will be locked after initial query executes
The warning indicates that the dialect you’re using would prefer if you locked the associated entities in a separate select statement, not using a join fetch.