-->
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.  [ 3 posts ] 
Author Message
 Post subject: Bidirectional associations performance
PostPosted: Fri Aug 05, 2005 1:01 pm 
Newbie

Joined: Mon Dec 27, 2004 1:18 pm
Posts: 4
Hi,

I am working with a bidirectional one to many association between two classes. In order to associate both objects, I had created a helper method

This helper method is basically as follows:

element1.setElement2(element2)
element2.getElements1().add(element1)

my problem comes with the performance of this. When I execute the second line, hibernate execute a Sql like:
select element1.* from element1 where element.element2_fk=element2.id.

My problem comes because this sql get a lot of time and I suppose that it is loading a lot of objects in memory that I do not really want in.

In some load test that I had done, with a unidirectional association it takes a couple of hours to run the test, and with bidirectional associations it takes about 8 hours to do the same test.
For the bidirectional association I had also created a index on the foreign key constrain (because otherwise it was taking even more...)

I had also enabled lazy loading for associations and proxies in a mapping as follows, and I am also using EhCache.
Code:
    <class name="element2" table="element2" proxy="element2" dynamic-insert="true" dynamic-update="true">
        <cache usage="read-write" />
        <id name="id" type="java.lang.String" unsaved-value="null">
            <column name="ID" sql-type="CHARACTER VARYING(1024)"/>
            <generator class="uuid.hex">
            </generator>
        </id>
        <version name="version" type="int" column="version"/>
        <property name="fefecto" type="java.util.Date">
            <column name="FEFECTO" not-null="false" unique="false" sql-type="DATE"/>
        </property>
        <set name="element1" lazy="true" outer-join="auto" inverse="true">
            <cache usage="read-write" />
            <key foreign-key="element2_fk">
                <column name="element2_fk"/>
            </key>
            <one-to-many class="element1"/>
        </set>
    </class>


is there any way of avoiding this select, or make it faster?

thanks in advance
Carlos Cuenca


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 05, 2005 2:31 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Use a bag. (This is in the docs!)


(Also, in HB 3.1, we have introduced lazy="extra", to allow for efficient "large" collections.)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 05, 2005 2:46 pm 
Newbie

Joined: Mon Dec 27, 2004 1:18 pm
Posts: 4
Thank you! I will make some test now.

(Also next time I will read docs more carefully)

Carlos Cuenca


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.