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