-->
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: Native Query returns wrong column value
PostPosted: Tue Nov 20, 2007 10:29 am 
Pro
Pro

Joined: Tue Jun 12, 2007 4:13 am
Posts: 209
Location: Berlin, Germany
I'm having trouble with a native query which I formulated as:

"SELECT si.inst_number, c.name, feat.name, " +
"a.POSTALCODE, a.CITY, a.STREET, a.STREETNO " +
"FROM institution si " +
"inner join FEATUREITEM feat on si.STATUS=feat.ID " +
"left outer join CONTACTS c on si.INST_CONTACT_ID = c.ID " +
"left outer join address a on c.id = a.contact_id " +
"WHERE length(si.INST_NUMBER) > 5 ORDER by si.inst_number";

The problem is, that the returned object[] has the same values for two columns in object[1] and object[2].

If I put the SQL into a SQL Tool and let it process, this brings the right values.
It seems to me that Hibernate is confused by "c.name" and "feat.name" and it sees only "name". Is that true?

And: do you think it is better to use JPA-QL here? If, how can I formulate it. I have the following associations:
Institution -> Contact -> Address, where Address may appear more than once for one Contact, whereas Institution has exactly one Contact.

Any suggestions welcome!
Carlo


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 22, 2007 9:24 am 
Pro
Pro

Joined: Tue Jun 12, 2007 4:13 am
Posts: 209
Location: Berlin, Germany
Hi,

I finally found that the cause confusing Hibernate. When executing the query "SELECT si.inst_number, c.name, feat.name...", that means Hibernates sees two attributes both named "name", because no aliases were given.

When I changed the code to this: "SELECT si.inst_number as InstNumber, c.name as contactName, feat.name as instStatus" I ran into an SQLException untitl I found out that the cause was the new MySQL driver (5.1.5). When I switched back to my former version(5.0.7), everything was as expected.

Carlo


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.