[
http://opensource.atlassian.com/projects/hibernate/browse/HHH-2676?page=c...
]
Emmanuel Bourg commented on HHH-2676:
-------------------------------------
Gavin's advice doesn't help if you intent to update the table after the select
query and require an exclusive write access.
What's missing to lift the 'Awaiting Test Case' status on this issue?
Cannot apply UPGRADE lock to scalar Query object
------------------------------------------------
Key: HHH-2676
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-2676
Project: Hibernate3
Issue Type: Bug
Components: query-hql
Affects Versions: 3.1
Reporter: John Wood
Priority: Minor
Attachments: Bean.hbm.xml, Bean.java
If you try and add a lock to a Query object (against a named alias) when doing a scalar
HQL query (e.g. "select sum(foo) from bah") then an error occurs.
The sample code (full working example is attached):
// Create query
Query q = session.createQuery("select b.value from Bean b");
// Set lock mode on query
q.setLockMode("b", LockMode.UPGRADE);
// Executre
q.list();
This causes the following error:
Exception in thread "main" java.lang.IllegalArgumentException: could not
locate alias to apply lock mode : b
at org.hibernate.loader.hql.QueryLoader.applyLocks(QueryLoader.java:297)
at org.hibernate.loader.Loader.preprocessSQL(Loader.java:201)
at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1538)
at org.hibernate.loader.Loader.doQuery(Loader.java:673)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
at org.hibernate.loader.Loader.doList(Loader.java:2220)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2104)
at org.hibernate.loader.Loader.list(Loader.java:2099)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:378)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:338)
at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:172)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1121)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
I have tried this both with an older version of Hibernate (3.1) and the latest with the
same result (although the older Hibernate has the error message "alias not
found".
I have attached a simple example to demonstrate this.
See also HHH-1965.
Perhaps, it is simply that one cannot lock scalar queries of this type. If so, then the
fix would presumably be to include this in the Query class Javadocs.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira