Hi,
I've been playing around with associations, fetch modes and outer-join options. I'm using Hibernate 3.2.6
It seems to me that my options are getting ignored. Can someone enlighten as to how I can leverage these options ?
Here is my usecase:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.archinsurance.rdm.entity.packages.impl">
<class name="RefReleasePackageImpl" table="REF_RELEASE_PACKAGE">
<id column="RELEASE_PACKAGE_ID" name="id" type="long">
<generator class="sequence">
<param name="sequence">SEQ_RELEASE_PACKAGE_ID</param>
</generator>
</id>
<property name="releasePackageNm" column="RELEASE_PACKAGE_NM" />
<one-to-one name="workspaceMetaState" class="WorkspaceMetaStateImpl" property-ref="workspaceMetaStateCustomJoin"
outer-join="true" lazy="false" fetch="join">
<formula>RELEASE_PACKAGE_NM</formula>
</one-to-one>
</class>
<class name="WorkspaceMetaStateImpl" table="ALL_WORKSPACES" mutable="false" >
<id column="WORKSPACE" name="id" type="string" />
<properties name="workspaceMetaStateCustomJoin">
<property name="id" column="WORKSPACE" insert="false" update="false"/>
</properties>
<property name="freezeStatus" column="FREEZE_STATUS" type="freezeStatus"/>
</class>
</hibernate-mapping>
ok im using a non-primary join but I know this part is working because I get N+1 selects when loading the associations with the below code:
Code:
Query query = entityManager.createQuery("select r from RefReleasePackageImpl r order by r.id");
releasePackagesResult = query.getResultList();
Now I thought that outer-join="true" on the association would result in 1 SQL query outer-joined but it results in N+1 selects. To avoid that I have to put: join fetch r.workspaceMetaState in my HQL query. Isn't the outer-join setting supposed to be the default behavior when no HQL clause is overriding it ?
PS: lazy="false" does some to have an effect because it loads the association eagerly on the query execution, the only problem I have is with the outer-join not triggering.
What are the conditions that need to be fulfilled for the outer-join="true" to work ?
Thanks,
-Guillaume