-->
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.  [ 1 post ] 
Author Message
 Post subject: <sql-query> bug(?) : problem building a join condition
PostPosted: Tue Jun 24, 2008 7:03 am 
Newbie

Joined: Fri Dec 14, 2007 8:34 am
Posts: 3
I have following in the hibernate mapping file...

<hibernate-mapping .....>
<class="CustomerImpl" table="cutomer">
<id name="customerNo" not-null="true" unique="true" sql-type="INTEGER">
<column name="c_cno">
</id>
...

<join table="customerExtn">
<key column="cx_cno" unique="true"/>
...
</join>
</class>

<sql-query name="customers.for.address">
<return alias="cust" class="CustomerImpl" />
<![CDATA[
select {cust.*}
from customer cust
where cust.c_cno in (select ca.ca_cno
from custAddresses ca
where lower(ca.ca_address) like lower(:address))
]]>
</sql-query>
</hibernate-mapping>


Now, The problem is my CustomerImpl class maps to 2 tables 'customer' and 'customerExtn'.

When the specified <sql-query> is formed on the run time it looks something like...

select cust.c_cno, cust.c_cname, ..., cust_1_.deptNo
from customer cust
where cust.c_cno in (select ca.ca_cno
from custAddresses ca
where lower(ca.ca_address) like lower(?))


It throws an error saying 'cust_1_' can not be referenced. It is trying refer to the 'customerExtn' table but customerExtn table is not referenced in the 'From clause' inspite of specifying the <join> in the 'CustomerImpl' class.

I have done a nasty hack to make it work. Looks like...

From customer cust join customerExtn cust_1_ on cust.c_cno=cust_1_.ca_cno

But, this is not an ideal solution as 'cust_1_' is generated by hibernate at the run time.

Has anyone come across something of this sort before?
Please do let me know if there is a way around it.
Many Thanks,
Jeevan.


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

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.