-->
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: outer-join on associations
PostPosted: Tue Jun 03, 2008 11:26 am 
Beginner
Beginner

Joined: Mon Mar 31, 2008 10:05 am
Posts: 20
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


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 03, 2008 1:38 pm 
Beginner
Beginner

Joined: Mon Mar 31, 2008 10:05 am
Posts: 20
By reading other posts, such as this one: http://forum.hibernate.org/viewtopic.php?t=924674, it seems like HQL will ignore any outer-join setting which is only useful if you are using Session.load(). This post is pretty old but I would guess that the information about outer-join is still current today.

I have to conclude that outer-join setting is useless if you use the JPA API which does not expose Session.load() but only EntityManager.find() which ignores as well outer-join.

I hope this will save some people some hassle.


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.