-->
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.  [ 2 posts ] 
Author Message
 Post subject: Hibernate changes my Result Array (many values equal)
PostPosted: Mon Aug 02, 2010 11:23 am 
Newbie

Joined: Tue Sep 15, 2009 5:25 am
Posts: 8
This is my query... (sorry ^^)

Code:
SELECT fbStart.abfahrt, fbDest.ankunft, fbStart.id, fb11.id as id11, fb12.id as id12, fbDest.id, 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


MySQL Workbench returns valid results:
'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'

But Hibernate gives:
<1201> <1358> <12195> <12195> <12195> <12195> <16> <97>
<1201> <1358> <12195> <12195> <12195> <12195> <16> <97>
<1229> <1405> <1642> <1642> <1642> <1642> <21> <116>
<1221> <1405> <11855> <11855> <11855> <11855> <20> <124>
<1221> <1405> <11855> <11855> <11855> <11855> <21> <124>
<1221> <1405> <11855> <11855> <11855> <11855> <21> <124>

All the Ids always have the same value... Ideas? This seems to be a weird behavious to me.

Thanks very much in advance.


Top
 Profile  
 
 Post subject: Re: Hibernate changes my Result Array (many values equal)
PostPosted: Fri Aug 06, 2010 3:23 am 
Newbie

Joined: Tue Sep 15, 2009 5:25 am
Posts: 8
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


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

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.