Hibernate version: 2.1.7
Full stack trace of any exception that occurs:
10:27:06,756 WARN JDBCExceptionReporter:57 - SQL Error: 0, SQLState: 42703
10:27:06,756 ERROR JDBCExceptionReporter:58 - The column name id0_ was not found in this ResultSet.
10:27:06,787 WARN JDBCExceptionReporter:57 - SQL Error: 0, SQLState: 42703
10:27:06,787 ERROR JDBCExceptionReporter:58 - The column name id0_ was not found in this ResultSet.
net.sf.hibernate.exception.SQLGrammarException: error performing findBySQL
at net.sf.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:59)
at net.sf.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:30)
at net.sf.hibernate.impl.SessionImpl.convert(SessionImpl.java:4110)
at net.sf.hibernate.impl.SessionImpl.findBySQL(SessionImpl.java:3858)
at net.sf.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:52)
at nl.qqq.emr.dao.TransportDaoImpl.getAllTransports(TransportDaoImpl.java:422)
at test.DaoTest.testGetAllTransports(DaoTest.java:198)
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:585)
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.junit3.JUnit3TestReference.run(JUnit3TestReference.java:128)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Caused by: org.postgresql.util.PSQLException: The column name id0_ was not found in this ResultSet.
Name and version of the database you are using: PostGreSQL 8.1.x
The generated SQL (show_sql=true):
select r.modeid as ModeID1_,
t.commodityGroupid as Commodit3_0_,
t.containerindicatorid as Containe4_0_,
t.loadindicatorid as LoadIndi5_0_,
sum(volume) / count(distinct year)
from transport t inner join route r on t.routeid = r.id
where r.originzoneid in (select id from zone where emrcode = ?) and
r.destinationzoneid in (select id from zone where emrcode = ?)
group by r.modeid, t.commodityGroupid, t.containerindicatorid, t.loadindicatorid
order by r.modeid, t.commodityGroupid, t.containerindicatorid, t.loadindicatorid
Hi all,
Im trying to perform a native SQL with createSQLQuery(..), the exact generated SQL which I add as a parameter in this method looks like this:
Code:
String avgStr = select r.modeid as {r.mode}, t.commodityGroupid as {t.commodityGroup}, t.containerindicatorid as {t.containderindicator}, t.loadindicatorid as {t.loadindicator}, (sum(volume) / count(distinct year))
from transport t inner join route r on t.routeid = r.id
where r.originzoneid in (select id from zone where emrcode = :origin) and r.destinationzoneid in (select id from zone where emrcode = :dest)
group by r.modeid, t.commodityGroupid, t.containerindicatorid, t.loadindicatorid
order by r.modeid, t.commodityGroupid, t.containerindicatorid, t.loadindicatorid
And this is how I call this method:
Code:
query = getSession().createSQLQuery(
avgStr,
new String[] {"t", "r"},
new Class[] {Transport.class, Route.class});
.
.
.
return query.setString("origin", origin)
.setString("dest", destination)
.list()
.iterator();
When I run this code, I get an error msg (see above) which I dont understand.
It says that id_0 is not found in the resultset. What does that mean ? I dont see any id_0 variable when I turn on show_sql:true.
Any help would be appreciated.
Thx.
PS: the only reason why Im using native SQL is that in HQL, I couldnt write: "(sum(volume) / count(distinct year))". When you do this, you get a syntax error which says that "/" is not allowed (or something like that).