-->
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.  [ 4 posts ] 
Author Message
 Post subject: Criteria generate wrong SQL statement
PostPosted: Wed Feb 18, 2009 1:42 pm 
Newbie

Joined: Wed Feb 18, 2009 1:33 pm
Posts: 3
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: 3.2.6

Mapping documents:

Code between sessionFactory.openSession() and session.close():

criteria.setProjection(Projections.projectionList().add(Projections.sum("firstPass"),"firstPass")
.add(Projections.sum("total"),"total")
.add(Projections.sum("finalPass"),"finalPass")
.add(Projections.groupProperty("product"), "product")
.add(Projections.groupProperty("startTime"), "startTime")
.add(Projections.groupProperty("seq"), "seq"));


criteria.add(Restrictions.between("startTime", startDate, endDate));
criteria.addOrder(Order.desc("startTime"));




Full stack trace of any exception that occurs:
Caused by: java.sql.SQLException: ORA-00904: "Y4_": invalid identifier

at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:125)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:316)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:282)
at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:639)
at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:185)
at oracle.jdbc.driver.T4CPreparedStatement.execute_for_describe(T4CPreparedStatement.java:503)
at oracle.jdbc.driver.OracleStatement.execute_maybe_describe(OracleStatement.java:965)
at oracle.jdbc.driver.T4CPreparedStatement.execute_maybe_describe(T4CPreparedStatement.java:535)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1051)
at oracle.jdbc.driver.OracleStatement.doScrollExecuteCommon(OracleStatement.java:3807)
at oracle.jdbc.driver.OraclePreparedStatement.doScrollPstmtExecuteUpdate(OraclePreparedStatement.java:9209)
at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:2982)
at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:3026)
at org.apache.commons.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:92)
at org.apache.commons.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:92)
at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:186)
at org.hibernate.loader.Loader.getResultSet(Loader.java:1787)
at org.hibernate.loader.Loader.scroll(Loader.java:2286)
... 30 more



Name and version of the database you are using: Oracle 11g

The generated SQL (show_sql=true):
select
sum(this_.first_pass) as y0_,
sum(this_.total) as y1_,
sum(this_.final_pass) as y2_,
this_.product_id as y3_,
this_.start_time as y4_,
this_.seq as y5_
from
app_yield_report this_
where
y4_ between ? and ?
group by
this_.product_id,
this_.start_time,
this_.seq
order by
y4_ desc



Debug level Hibernate log excerpt:


The problem in here is Oracle doesn't know the y4_. I believe this is a bug


Problems with Session and transaction handling?

Read this: http://hibernate.org/42.html


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 18, 2009 1:48 pm 
Newbie

Joined: Wed Feb 18, 2009 1:33 pm
Posts: 3
if I removed the restrictions.between statement. it works.

criteria.add(Restrictions.between("startTime", startDate, endDate));



it generates



select
sum(this_.first_pass) as y0_,
sum(this_.total) as y1_,
sum(this_.final_pass) as y2_,
this_.product_id as y3_,
this_.start_time as y4_,
this_.seq as y5_
from
app_yield_report this_
group by
this_.product_id,
this_.start_time,
this_.seq
order by
y4_ desc


which it works.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 18, 2009 2:43 pm 
Newbie

Joined: Wed Feb 18, 2009 1:33 pm
Posts: 3
The only way I can make it work is to use Restriction.sqlRestriction().


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 19, 2009 8:32 am 
Expert
Expert

Joined: Thu Jan 08, 2009 6:16 am
Posts: 661
Location: Germany
I guess what you want is a having-clause, which is currently not supported by criteria.

_________________
-----------------
Need advanced help? http://www.viada.eu


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.