-->
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.  [ 1 post ] 
Author Message
 Post subject: Cant select an aggregated date comparison using sysdate
PostPosted: Wed Jun 28, 2006 5:34 pm 
Newbie

Joined: Wed May 25, 2005 2:28 pm
Posts: 5
Hibernate version: 3.0
Name and version of the database you are using: Oracle 10g (ojdbc14.jar)

Let's say I'm making a vehicle inventory system and want to find out the average number of days my vehicles have been in the inventory.

Oracle query:
Code:
select avg(sysdate - date_in) from inventory
-- works perfectly, oracle returns DATE subtractions as floats in days


HQL :
Code:
select new com.whatever.InventoryStatus(avg(sysdate - inv.dateIn))
from Inventory inv
-- Note that I have also tried sysdate() and current_date(), neither of which worked.


Generated SQL ( pulled via debug in QueryTranslatorImpl.renderSQL() ):
Code:
select avg(sysdate-inventory0_.DATE_IN) as col_0_0_ from INVENTORY inventory0_
-- looks ok!


Return Types (value of QueryTranslatorImpl.returnTypes):
org.hibernate.type.DateType
org.hibernate.type.TimestampType

So here's my problem: what's that extra return type doing there? It's causing the ReflectionHelper to fail to find a two-arg constructor. Even worse, its a double constructor, since avg() returns a single double value. I've also drastically simplified this example. With a couple joins, and a 3-arg constructor, this balloons to 28 returnTypes!

Thanks in advance for any help.


Stack trace:
Code:
org.hibernate.PropertyNotFoundException: no appropriate constructor in class: com.whatever.InventoryStatus
        at org.hibernate.util.ReflectHelper.getConstructor(ReflectHelper.java:230)
        at org.hibernate.hql.classic.QueryTranslatorImpl.renderSQL(QueryTranslatorImpl.java:586)
        at org.hibernate.hql.classic.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:180)
        at org.hibernate.hql.classic.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:152)
        at org.hibernate.impl.SessionFactoryImpl.getQuery(SessionFactoryImpl.java:425)
        at org.hibernate.impl.SessionImpl.getQueries(SessionImpl.java:880)
        at org.hibernate.impl.SessionImpl.list(SessionImpl.java:830)
        at org.hibernate.impl.QueryImpl.list(QueryImpl.java:74)


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

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.