I noticed that all of the problematic columns MySQL Workbench returns are named "id" and suspected the problem there. I aliased all the returning values to "idS", "id11", "id12", "id21", "id22", "idXY"... and "idD". Now Hibernate throws an error:
Quote:
8328 [main] INFO org.hibernate.type.IntegerType - could not read column value from result set: id; Column 'id' not found.
8329 [main] WARN org.hibernate.util.JDBCExceptionReporter - SQL Error: 0, SQLState: S0022
8329 [main] ERROR org.hibernate.util.JDBCExceptionReporter - Column 'id' not found.
Exception in thread "main" org.hibernate.exception.SQLGrammarException: could not execute query
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:92)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
at org.hibernate.loader.Loader.doList(Loader.java:2297)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2172)
at org.hibernate.loader.Loader.list(Loader.java:2167)
at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:316)
at org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1832)
at org.hibernate.impl.AbstractSessionImpl.list(AbstractSessionImpl.java:165)
at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:179)
at de.taf.easygo.modules.timetable.hafas.Request.getConnections(Request.java:348)
at de.taf.easygo.modules.timetable.hafas.Request.main(Request.java:1036)
Caused by: java.sql.SQLException: Column 'id' not found.
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1075)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:989)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:984)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:929)
at com.mysql.jdbc.ResultSetImpl.findColumn(ResultSetImpl.java:1145)
at com.mysql.jdbc.ResultSetImpl.getInt(ResultSetImpl.java:2814)
at org.hibernate.type.IntegerType.get(IntegerType.java:51)
at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:186)
at org.hibernate.type.NullableType.nullSafeGet(NullableType.java:212)
at org.hibernate.loader.custom.CustomLoader$ScalarResultColumnProcessor.extract(CustomLoader.java:501)
at org.hibernate.loader.custom.CustomLoader$ResultRowProcessor.buildResultRow(CustomLoader.java:447)
at org.hibernate.loader.custom.CustomLoader.getResultColumnOrRow(CustomLoader.java:344)
at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:647)
at org.hibernate.loader.Loader.doQuery(Loader.java:745)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:270)
at org.hibernate.loader.Loader.doList(Loader.java:2294)
... 8 more
Changed the query the following way:
Code:
SQLQueryImpl(SELECT fbStart.abfahrt, fbDest.ankunft, fbStart.id as idS, fb11.id as id11, fb12.id as id12, fbDest.id as idD, fb11.id - fbStart.id + fbDest.id - fb12.id AS dist, ((FLOOR(fbDest.ankunft / 100) * 60) + (fbDest.ankunft % 60)) - ((FLOOR(fbStart.abfahrt / 100) * 60) + (fbStart.abfahrt % 60)) AS timeDiff
FROM FahrtBahnhof AS fbStart
JOIN FahrtVerkehrstage AS fvStart ON fvStart.fahrt_id = fbStart.fahrt_id
JOIN Bitfeld AS bfStart ON bfStart.nummer = fvStart.bitfeld_nummer AND SUBSTRING(CONV(SUBSTRING(bfStart.bitfeld, 2, 1), 16, 2), -1, 1) = 1
JOIN FahrtBahnhof AS fb11 ON fb11.fahrt_id = fbStart.fahrt_id AND fb11.id > fbStart.id
JOIN FahrtLinie AS fl11 ON fl11.fahrt_id = fb11.fahrt_id AND (fl11.vonBahnhof_nummer IS NULL OR fl11.vonBahnhof_nummer <= fb11.bahnhof_nummer) AND (fl11.bisBahnhof_nummer IS NULL OR fl11.bisBahnhof_nummer >= fb11.bahnhof_nummer)
JOIN FahrtVerkehrstage AS fv11 ON fv11.fahrt_id = fb11.fahrt_id
JOIN Bitfeld AS bf11 ON bf11.nummer = fv11.bitfeld_nummer AND SUBSTRING(CONV(SUBSTRING(bf11.bitfeld, 2, 1), 16, 2), -1, 1) = 1
JOIN FahrtBahnhof AS fb12 ON fb12.bahnhof_nummer = fb11.bahnhof_nummer AND fb12.fahrt_id != fb11.fahrt_id AND fb12.abfahrt > fb11.ankunft
JOIN FahrtLinie AS fl12 ON fl12.fahrt_id = fb12.fahrt_id AND (fl12.vonBahnhof_nummer IS NULL OR fl12.vonBahnhof_nummer <= fb12.bahnhof_nummer) AND (fl12.bisBahnhof_nummer IS NULL OR fl12.bisBahnhof_nummer >= fb12.bahnhof_nummer) AND fl12.linie_id != fl11.linie_id
JOIN FahrtVerkehrstage AS fv12 ON fv12.fahrt_id = fb12.fahrt_id
JOIN Bitfeld AS bf12 ON bf12.nummer = fv12.bitfeld_nummer AND SUBSTRING(CONV(SUBSTRING(bf12.bitfeld, 2, 1), 16, 2), -1, 1) = 1
JOIN FahrtBahnhof AS fbDest ON fbDest.fahrt_id = fb12.fahrt_id AND fbDest.id > fb12.id
JOIN FahrtVerkehrstage AS fvDest ON fvDest.fahrt_id = fbDest.fahrt_id
JOIN Bitfeld AS bfDest ON bfDest.nummer = fvDest.bitfeld_nummer AND SUBSTRING(CONV(SUBSTRING(bfDest.bitfeld, 2, 1), 16, 2), -1, 1) = 1
WHERE fbStart.bahnhof_nummer = 153075 AND fbDest.bahnhof_nummer = 174215 AND fbStart.abfahrt >= 1200 AND fbStart.abfahrt <= 1230
ORDER BY fbDest.ankunft, timeDiff, dist LIMIT 6)
Why does Hibernate search for a column named "id"?
MySQL Workbench still returns the expected result (with altered column names as I have given them in the query).
abfahrt, ankunft, idS, id11, id12, idD, dist, timeDiff
'1201', '1358', '12195', '12209', '6786', '6788', '16', '97'
'1201', '1358', '12195', '12210', '6787', '6788', '16', '97'
'1229', '1405', '1642', '1644', '12230', '12249', '21', '116'
'1221', '1405', '11855', '11859', '12233', '12249', '20', '124'
'1221', '1405', '11855', '11857', '12230', '12249', '21', '124'
'1221', '1405', '11855', '11858', '12231', '12249', '21', '124'
Please this is extremely urgent. (university thesis)
Every idea appreciated.
Regards,
annih