The query.setXxx methods are pretty good about detecting attempts to set things which don't exist in your query, can setLockMode be made to also do this?
Details leading to the above request:
This worked in hibernate2. In hibernate3, its attempting to lock a null table. Ok, I see the problem in the below (marked with BAD LINE), however, i'll post this anyway (with the above request, and to assist anyone else searching for help with a similar message from their database) as hibernate generated a bad query, and left it up to the database to get upset about it.
Hibernate version: 3.0rc1
Code between sessionFactory.openSession() and session.close():
eiQ = hsession.createQuery("from EquipmentInstance as ei where ei.id =
:id");
eiQ.setLockMode("ei", LockMode.UPGRADE);
eQ = hsession.createQuery("from Entity as e where e.id =
:id");
eQ.setLockMode("e", LockMode.UPGRADE);
ei2aQ = hsession.createQuery("from
EquipmentInstance2Attribute as ei2a where ei2a.id = :id");
-->BAD LINE (should be ei2aQ): eQ.setLockMode("ei2a", LockMode.UPGRADE);
...
eQ.setString("id", eimw.getStrVal());
e = (Entity)eQ.uniqueResult();
Full stack trace of any exception that occurs:
(postgres log info:)
2005-03-10 18:29:58 ERROR: syntax error at or near "null" at character 364
2005-03-10 18:29:58 LOG: statement: rollback; begin;
2005-03-10 18:29:58 LOG: statement: end
Name and version of the database you are using:
PostgreSQL 8.0
The generated SQL (show_sql=true):
Hibernate: select entity0_.id as id, entity0_.active_dts as active2_0_,
entity0_.deactive_dts as deactive3_0_, entity0_.first_name as first4_0_,
entity0_.last_name as last5_0_, entity0_.company as company0_,
entity0_.comment as comment0_, entity0_.special_code as special8_0_,
entity0_.entity_type_id as entity9_0_ from entity entity0_ where
(entity0_.id=?) for update of null, entity0_
_________________ The second 'u' in 'nuclear' is silent, dagnabit!
|