hi,
i have similar problems. My hibernate query is:
select avg(o.totalPrice * c.exchangeRate)
from LightOrder o, Currency c
where c.isoCurrency = o.currencyIso AND
o.createdTs >= '1096934400000'
AND o.createdTs < '1097020800000'
AND o.testStatus = 0
AND o.orderStatus = 1
AND ( o.mandantId = 19 OR o.mandantId = 35 )
GROUP BY c.exchangeRate
It will be translated to following SQL Query:
select avg(lightorder0_.total_price*currency1_.exchange_rate)
as x0_0_ from orders lightorder0_, currency currency1_
where (currency1_.iso_currency=lightorder0_.currency_iso )
AND(lightorder0_.created_TS>='1096934400000' )
AND(lightorder0_.created_TS<'1097020800000' )
AND(lightorder0_.test_status=0 )
AND(lightorder0_.order_status=1 )
AND((lightorder0_.mandant_id=19 )OR(lightorder0_.mandant_id=35 ))
group by currency1_.exchange_rate
This SQL _DOES_ perform on my Database as expected.
But Hibernate has problems to examine the ResultSet.
Code:
2004-11-15 16:35:53,415 WARN [main] (JDBCExceptionReporter.java:38) - SQL Error: 0, SQLState: S0022
2004-11-15 16:35:53,416 ERROR [main] (JDBCExceptionReporter.java:46) - Column 'x1_0_' not found.
2004-11-15 16:35:53,418 WARN [main] (JDBCExceptionReporter.java:38) - SQL Error: 0, SQLState: S0022
2004-11-15 16:35:53,419 ERROR [main] (JDBCExceptionReporter.java:46) - Column 'x1_0_' not found.
2004-11-15 16:35:53,448 ERROR [main] (JDBCException.java:38) - Could not execute query
java.sql.SQLException: Column 'x1_0_' not found.
at com.mysql.jdbc.ResultSet.findColumn(ResultSet.java:2278)
at com.mysql.jdbc.ResultSet.getInt(ResultSet.java:1289)
at net.sf.hibernate.type.IntegerType.get(IntegerType.java:18)
at net.sf.hibernate.type.NullableType.nullSafeGet(NullableType.java:62)
at net.sf.hibernate.type.NullableType.nullSafeGet(NullableType.java:53)
at net.sf.hibernate.hql.QueryTranslator.getResultColumnOrRow(QueryTranslator.java:985)
at net.sf.hibernate.loader.Loader.doQuery(Loader.java:222)
at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:133)
at net.sf.hibernate.loader.Loader.doList(Loader.java:950)
at net.sf.hibernate.loader.Loader.list(Loader.java:941)
at net.sf.hibernate.hql.QueryTranslator.list(QueryTranslator.java:834)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1512)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1491)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1483)
at com.maxviva.siteadmin.hibernate.base._BaseRootDAO.find(_BaseRootDAO.java:224)
at com.maxviva.siteadmin.hibernate.base._BaseRootDAO.find(_BaseRootDAO.java:212)
at com.maxviva.siteadmin.hibernate.dao.LightOrderDAO.getAvgBooking(LightOrderDAO.java:128)
at com.maxviva.siteadmin.stats.OrderStatsManager.getOrderStatistic(OrderStatsManager.java:505)
at com.maxviva.siteadmin.stats.OrderStatsManager.getDailyOrderStatistic(OrderStatsManager.java:492)
at com.maxviva.siteadmin.test.OrderStatsManagerTest.testGetOrders(OrderStatsManagerTest.java:74)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:421)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:305)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:186)
Any Idea?
Thanks in advace for Help.
Michael