-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Wrong sql generation - maybe Bug
PostPosted: Wed Apr 13, 2005 7:58 pm 
Regular
Regular

Joined: Thu Aug 28, 2003 6:30 am
Posts: 58
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.1

The 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);


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 12, 2006 8:49 am 
Regular
Regular

Joined: Wed Nov 17, 2004 11:49 am
Posts: 65
Location: Pittsburgh
I am having *exactly* the same problem on Hibernate 3.1 final. The code works fine with SQL Server. Is this a bug in Hibernate or a problem with Oracle?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 12, 2006 8:58 am 
Regular
Regular

Joined: Wed Nov 17, 2004 11:49 am
Posts: 65
Location: Pittsburgh
http://opensource.atlassian.com/project ... e/HHH-1168


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.