Hibernate version: Hibernate 3.0 release
Mapping documents:
Code:
<hibernate-mapping>
<class
name="com.mypck.jms.hibernate.LeadQueueItem"
table="lead_queue"
proxy="com.mypck.jms.hibernate.LeadQueueItem"
dynamic-update="true"
dynamic-insert="true"
mutable="true"
>
<id
name="id"
column="item_id"
type="long"
unsaved-value="-1"
>
<generator class="sequence">
<param name="sequence">lead_queue_seq</param>
</generator>
</id>
<property
name="creationTime"
type="long"
update="true"
insert="true"
column="creation_time"
not-null="true"
unique="false"
/>
<property
name="leadId"
type="long"
update="true"
insert="true"
column="lead_id"
not-null="true"
unique="false"
/>
<many-to-one
name="lead"
class="com.mypck.persistent.dao.hibernate.LeadHibernate"
cascade="none"
outer-join="false"
update="false"
insert="false"
column="lead_id"
not-null="true"
unique="false"
/>
<property
name="priority"
type="float"
update="true"
insert="true"
column="priority"
not-null="true"
unique="false"
/>
</class>
Code between sessionFactory.openSession() and session.close():
Code:
final Query query = getSession().createQuery("from LeadQueueItem item order by (item.creationTime/180000*item.priority)");
query.setLockMode("item", LockMode.UPGRADE);
query.setMaxResults(1);
final List result = query.list();
Full stack trace of any exception that occurs:
org.hibernate.exception.SQLGrammarException: could not execute query
at org.hibernate.exception.ErrorCodeConverter.convert(ErrorCodeConverter.java:70)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.loader.Loader.doList(Loader.java:1518)
at org.hibernate.loader.Loader.list(Loader.java:1498)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:369)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:266)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:804)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:74)
at com.mypck.jms.hibernate.DBLeadConsumer$NewLeadTransactionCallback.doInTransaction(DBLeadConsumer.java:86)
at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:114)
at com.mypck.jms.hibernate.DBLeadConsumer.processHightPriorityLeads(DBLeadConsumer.java:53)
at com.mypck.jms.hibernate.DBLeadConsumer.run(DBLeadConsumer.java:40)
at java.lang.Thread.run(Thread.java:512)
Caused by: java.sql.SQLException: ORA-00904: wrong column name
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:180)
at oracle.jdbc.oci8.OCIDBAccess.check_error(OCIDBAccess.java:1759)
at oracle.jdbc.oci8.OCIDBAccess.parseExecuteDescribe(OCIDBAccess.java:953)
at oracle.jdbc.driver.OracleStatement.doExecuteQuery(OracleStatement.java:2117)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:2331)
at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:422)
at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:366)
at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:118)
at org.hibernate.loader.Loader.getResultSet(Loader.java:1197)
at org.hibernate.loader.Loader.doQuery(Loader.java:366)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:206)
at org.hibernate.loader.Loader.doList(Loader.java:1515)
... 10 more
Name and version of the database you are using: Oracle 9.0.1The generated SQL (show_sql=true):
select * from ( select leadqueuei0_.item_id as item1_, leadqueuei0_.creation_time as creation2_5_, leadqueuei0_.lead_id as lead3_5_, leadqueuei0_.priority as priority5_ from lead_queue leadqueuei0_ order by leadqueuei0_.creation_time/180000*leadqueuei0_.priority ) where rownum <= ? for update of leadqueuei0_.item_id
I'm trying to get 1 row from db for update and Hibernate generates wrong sql for it :( Outer select knows nothing about leadqueuei0_.item_id.
P.S. When i want to select only some columns for update not all row. How can i do it? Because such code doesn't work
Code:
final Query query = getSession().createQuery("select item.leadId from LeadQueueItem item order by " +
"(item.creationTime/" + multiplier + "*item.priority)");
query.setLockMode("item", LockMode.UPGRADE);
or
Code:
final Query query = getSession().createQuery("select item.leadId from LeadQueueItem item order by " +
"(item.creationTime/" + multiplier + "*item.priority)");
query.setLockMode("item.leadId", LockMode.UPGRADE);