Hi!
I have a very funny problem with a "manual" hibernate sql query:
Simplified code:Code:
Query q = session.createSQLQuery("select t1.a, t1.b, t2.b from t1, t2 where t1.c = '007' and t1.a = t2.d");
List results = query.list();
The SQL Query executed in MySql returns something like:
Code:
'1', '2', '3'
'4', '5', '6'
'7', '8', '9'
The results I get from hibernate look like:
Code:
'1', '2', '2'
'4', '5', '5'
'7', '8', '8'
(the third column is always the same as the second).The hibernate result is "correct" when I use t1.anything_but_b instead of t1.b! So this only happens if two columns in two tables have the same name!Anybody any idea before I report this as a bug? The tables I query here are dynamically added at runtime and provide only configuration information (no mapping and all the good hibernate methods possible here).
Thank you very much in advance!!!
Regards,
Anton
----------------------------------------
Original generated code (maybe I am blind...):Code:
Query query = session.createSQLQuery(
"Select tmpljava_dimension_spec.code, tmpljava_dimension_spec.english, tmpljavadep_dimension_si_units.english " + // TODO: MLS
"from tmpljava_dimension_spec, tmpljavadep_dimension_si_units " +
"where tmpljava_dimension_spec.dim_specify like '" + dimCode + "' " +
"and tmpljava_dimension_spec.code = tmpljavadep_dimension_si_units.dim_code");
Logger.getLogger(TemplatingManagerImpl.class).debug(query);
List results = query.list();
for (Iterator<Object[]> i = results.iterator(); i.hasNext();) {
Object[] gugu = i.next();
for (int gaga = 0; gaga < gugu.length; gaga++) {
System.err.print(gugu[gaga] + ",");
}
System.err.println("");
}
Original output (part of) for SQL:
Code:
FORG_GKG NULL kg
FORG_GKG Weight kg
FORG_GKG NULL kg
KFZMOTOR_PS Power kW
Original output (part of) for the hibernate result:
Select tmpljava_dimension_spec.code, tmpljava_dimension_spec.english, tmpljavadep_dimension_si_units.english from tmpljava_dimension_spec dimspec, tmpljavadep_dimension_si_units where tmpljava_dimension_spec.dim_specify like '%' and tmpljava_dimension_spec.code = tmpljavadep_dimension_si_units.dim_code
Code:
FORG_GKG,null,null,
FORG_GKG,Weight,Weight,
FORG_GKG,null,null,
KFZMOTOR_PS,Power,Power,