-->
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.  [ 3 posts ] 
Author Message
 Post subject: Different columns are not different???
PostPosted: Thu Sep 24, 2009 1:30 am 
Newbie

Joined: Thu Sep 24, 2009 1:13 am
Posts: 2
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,


Top
 Profile  
 
 Post subject: Re: Different columns are not different???
PostPosted: Thu Sep 24, 2009 2:26 am 
Senior
Senior

Joined: Sat Nov 27, 2004 4:13 am
Posts: 137
I'm not sure, but try using aliases for your tables and reference the columns in select part via aliases.

_________________
don't forget to credit!

Amir Pashazadeh
Payeshgaran MT
پايشگران مديريت طرح
http://www.payeshgaran.co
http://www.payeshgaran.org
http://www.payeshgaran.net


Top
 Profile  
 
 Post subject: Re: Different columns are not different???
PostPosted: Thu Sep 24, 2009 12:30 pm 
Newbie

Joined: Tue Jan 06, 2009 5:03 am
Posts: 7
set show_sql to true and paste the genrated sql query .


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.