-->
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: HQL and join, wrong comparison
PostPosted: Tue Jun 01, 2004 7:19 am 
Regular
Regular

Joined: Tue May 11, 2004 9:23 am
Posts: 69
Hey,

I'm trying to write a HQL with join between 3 tables. Hibernate automatically performs the join but the problem is that it compares the wrong columns. The classes are CountryT, CustomerT, CustomerorderT.

CountryT - countrycode (PK)
CustomerT - countrycode, customerno (composite)
CustomerorderT - countrycode, customerorderno (composite)
(CustomerorderT also contains customerno but is not a part of the key. )

Relations:
CustomerorderT M:1 CustomerT
CustomerT M:1 CountryT

This is the HQL:
Code:
Query q = session.createQuery("SELECT co.customerT.firstname, co.customerT.lastname, "
+ "co.customerorderTPK.countryT.countryname, co.customerorderTPK.customerorderno "
+ "FROM net.sf.hibernate.CustomerorderT co");


With debugger:
Code:
11:21:13,418 DEBUG SQL:237 - select customert1_.FIRSTNAME as x0_0_, customert1_.LASTNAME as x1_0_, countryt2_.COUNTRYNAME as x2_0_, customeror0_.CUSTOMERORDERNO as x3_0_ from CUSTOMERORDER_T customeror0_, CUSTOMER_T customert1_, COUNTRY_T countryt2_ where customeror0_.COUNTRYCODE=customert1_.CUSTOMERNO and customeror0_.CUSTOMERNO=customert1_.COUNTRYCODE and customeror0_.COUNTRYCODE=countryt2_.COUNTRYCODE


As can be seen it compares countrycode with customerno ( customeror0_.COUNTRYCODE=customert1_.CUSTOMERNO and customeror0_.CUSTOMERNO=customert1_.COUNTRYCODE ) which of course is wrong. customerno is not a specific key in the CustomerorderT which make a line in a table unique. But I believe it should be used in the join, or am I wrong? But it seems like Hibernate doesn't find it.

I should be a fault in the relations but the code i generated in middlegen, both the xml and java files from the database.

So how do I solve this problem so the join becomes correct? Perhaps my query is wrong?


MVH Newman


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 02, 2004 5:49 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
USe the cvs version of middlegen, or manually check your mapping files
composite-id properties *must* be in the same order then the one in FKs (many-to-one)

_________________
Emmanuel


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.