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.TimestampTypeSo 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)