-->
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: Eager Fetching with bidirectional association
PostPosted: Wed Nov 01, 2006 5:04 pm 
Beginner
Beginner

Joined: Wed Jul 14, 2004 11:51 am
Posts: 43
Hibernate version: 3.1

Hi,

I am encountering a problem with bidrectional eager fetching (whether many-to-many or many-to-one) and do not know how to fix it.

I have 2 classes that are linked by a bidirectional many-to-many association: Product and Provider.

When I try to fetch (by load method) my Product object, I seem to get a cartesian join even though I specify to use the outer-join attribute (I can easily see this with the show_sql attribute).

If my relation is one sided, only one sql query is generated but when using a bidirectional association, I get a lot of sql queries

It is important to note that I do not wish to use lazy loading on my collections at this point.

Here are my mappings:

Code:
        <set
            name="providers"
            table="PRODUCTS2PROVIDERS"
            lazy="false"
            cascade="none"
            sort="org.mdarad.samples.totaltest.entities.ProviderComparator"
            outer-join="true">

            <key
                column="PRODUCTS_FK"
            >
            </key>

            <many-to-many
                class="org.mdarad.samples.totaltest.entities.Provider"
                column="PROVIDERS_FK"
                outer-join="true"
             />

        </set>

Code:

        <set
            name="products"
            table="PRODUCTS2PROVIDERS"
            lazy="false"
            cascade="none"
            sort="org.mdarad.samples.totaltest.entities.ProductComparator"
            outer-join="true"
            inverse="true">

            <key
                column="PROVIDERS_FK"
            >
            </key>

            <many-to-many
                class="org.mdarad.samples.totaltest.entities.Product"
                column="PRODUCTS_FK"
                outer-join="true"
             />

        </set>


Any idea how I can fix this to have my eager fetch not end up as a cartesian join for my bidirectional associations?

Thanks,

Francois
Post rating: This posting has not been rated so far.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 02, 2006 1:31 pm 
Beginner
Beginner

Joined: Wed Jul 14, 2004 11:51 am
Posts: 43
Hmm....finally I think this is normal behaviour since I will try to load all the providers of a product, then all the products of this provider and so on and so forth.

It is rather a bad design than an issue...


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.