-->
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: Query many to many
PostPosted: Wed Dec 24, 2008 8:28 am 
Newbie

Joined: Wed Oct 15, 2008 12:43 pm
Posts: 4
I have two tables: Customer and State. These two tables are linked by m:m relationship.

So there is customer_state table.

Customer: 8000 rows
cust_num
f_name
l_name
state_Code

State: 36,000 rows
state_Code
state_Desc

Customer_state:
cust_num
state_code

I have the following query in hbm:

<set
name="states" fetch="join" table="customer_state" lazy="false"
>
<key column="cust_num" />
<element type="string" column="state_code"/>
</set>

When run, it is executing the following query for each customer. So for each 8000 rows, it is substituing
cust_num in the following query.


select
cust.cust_num as customer1_1_0_,
cust.FIRST_NAME as FIRST4_1_0_,
..(all columns of cust)
st.cust_num as customer1_2_,
st.state_code as st2_2_
from
customer cust,
state st
where
cust.cust_num=st.cust_num(+)
and cust.cust_num= '02066165'

So my question is, is there any way to fetch all the rows at once without going through each row of
customer_number and executing the above.

In otherwords, I need the result of the following without cust_number mentioned.
select
cust.cust_num as customer1_1_0_,
cust.FIRST_NAME as FIRST4_1_0_,
..(all columns of cust)
st.cust_num as customer1_2_,
st.state_code as st2_2_
from
customer cust,
state st
where
cust.cust_num=st.cust_num(+)


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.