Java – use hibernate 4 and Postgres’s “select for update of”
I'm using Postgres 9.3 5 and recently updated hibernate from 3.2 to 4.3 eleven
As a result, I couldn't run the "select... For update of" query, and just 'select 'for update' is not enough in my case because it returns
The criteria I try to use are as follows:
Criteria criteria = session.createCriteria(objectType).add(Restrictions.eq("name",objectName).ignoreCase());
I am using the following locks:
3.2: criteria setLockMode(LockMode.UPGRADE);
In 4.3 11 medium: criteria setLockMode(LockMode.PESSIMISTIC_WRITE);
I have a hierarchy of Hibernate (& dB) objects, which causes hibernate to execute multiple connections when constructing the above query‘ ObjectType 'is a connected subclass of the main class
<class name="BaSEObject" table="BASE_OBJECTS">
When using hibernate 3.2, the final query (taken from the Postgres log) reads: "update this_2_" End (when this_2_ is the alias given by hibernate to the mapped main table (baseobject) in hbm.xml file)
Upgrade to 4.3 After 1.1, the same query returns the above exception This means that the final query executed for the update (there is no name of the table to lock)
After extensive Internet browsing, I found that only the "for update of" of hibernate and Postgres are no longer supported?
[ https://hibernate.atlassian.net/browse/HHH-5654 ][2]
It seems unlikely because it is a very important SQL function and usage has decreased significantly
Did I miss anything here?
September 2, 2015:
I will try my best to clarify myself:
Using the example given in the hibernate documentation
class name="Payment" table="PAYMENT"> <id name="id" type="long" column="PAYMENT_ID"> <generator class="native"/> </id> <property name="amount" column="AMOUNT"/> ... <joined-subclass name="CreditCardPayment" table="CREDIT_PAYMENT"> <key column="PAYMENT_ID"/> <property name="creditCardType" column="CCTYPE"/> ... </joined-subclass> <joined-subclass name="CashPayment" table="CASH_PAYMENT"> <key column="PAYMENT_ID"/> ... </joined-subclass> <joined-subclass name="ChequePayment" table="CHEQUE_PAYMENT"> <key column="PAYMENT_ID"/> ... </joined-subclass>
If I want to do the following: select P from payment P, where id = 1
Hibernate will perform external joins on all tables (on keys)
Adding a lock (. Setlockmode (lockmode. Pessimistic_write)) will lock rows on four tables (such as' for update '), not just in the table "payment" ('update p') – this does happen in Hibernate 3.2
So what we have is that the early things provided by hibernate no longer use their own mapping examples?
Thank you in advance
Solution
The problem has been fixed in Hibernate 5 Test in 5.2 8.Final.