Issue
I don't really want to lock rows, I want to use a table level lock (Postgres' LOCK TABLE MyTable in ACCESS exclusive MODE`) as a method of synchronizing access around a sequence (only increment it once, when a certain condition holds). Though the "certain condition" does involve rows, I want to count them, not retrieve them and lock on them.
Does Hibernate support full table locks?
Solution
That's not possible through JPQL/HQL. You will have to execute a native query for doing the locking e.g. entityManager.createNativeQuery("LOCK TABLE MyTable in ACCESS exclusive MODE").executeUpdate()
Answered By - Christian Beikov