-->
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.  [ 1 post ] 
Author Message
 Post subject: difference between <return-join> and multiple <retu
PostPosted: Fri Apr 07, 2006 9:34 pm 
Newbie

Joined: Fri Apr 07, 2006 9:18 pm
Posts: 3
Hibernate version: 3.1.2

I am trying to eagerly populate a many-to-one reference in a native sql query. I thought I had it figured out when I came across the <return-join> element until I realized that the collection being returned was not a collection of my persistent class, but was actually a collection of Obect[].

So my question becomes when is return-join different that just using multiple return elements? They seem to behave in the same way as far as I can tell (at least in my case).

Secondarily, is there any way to use a native sql query, eagerly fetch foreign key references, and still return a collection of the persistent class being queried?

I have seen other people reference similar issues, and I have also reviewed the unit tests (JoinFetchTest) and confirmed that the behavior I am seeing matches the tests, but I just don't understand why this behaves so differently than a "left join fetch" in HQL.

So, now for the relevent bits of code. Here's the class I'm querying:

@Entity(access=AccessType.FIELD)
@Table(name="Procedures")
public class Procedure extends ValueObject
implements Serializable
{
...Base properties omitted for brevity
@ManyToOne()
@JoinColumn(name="iAssetTypeId")
private AssetType _assetType;

...Getters/Setters omitted too.
}

And the two, seemingly equivilent named queries (both return collections of object[])

<sql-query name="procedureBySiteAndNameReturnJoin">
<return alias="p" class="com.itendant.bo.procedure.Procedure"/>
<return-join alias="a" property="p._assetType"/>
SELECT {p.*}, {a.*}
FROM ProcedureLibrary pl,
ServiceProvider sp,
Procedures p,
AssetType a
WHERE pl.iServiceProviderId = sp.iId
AND p.iProcedureLibraryId = pl.iId
AND p.iAssetTypeId = a.iId
AND sp.iSiteId = :iSiteId
AND UPPER(p.sName) LIKE UPPER(:sNameLike)
</sql-query>

<sql-query name="procedureBySiteAndNameMultiReturn">
<return alias="p" class="com.itendant.bo.procedure.Procedure"/>
<return alias="a" class="com.itendant.bo.assettype.AssetType"/>
SELECT {p.*}, {a.*}
FROM ProcedureLibrary pl,
ServiceProvider sp,
Procedures p,
AssetType a
WHERE pl.iServiceProviderId = sp.iId
AND p.iProcedureLibraryId = pl.iId
AND p.iAssetTypeId = a.iId
AND sp.iSiteId = :iSiteId
AND UPPER(p.sName) LIKE UPPER(:sNameLike)
</sql-query>

Thanks in advance for any help/explanation,
Scott


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.