-->
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: Custom SQL for Lazy association fetch?
PostPosted: Tue Dec 16, 2008 8:55 pm 
Newbie

Joined: Tue Dec 16, 2008 8:47 pm
Posts: 3
Hi There,

I'm dealing with a very poorly architected database that has been around since the dawn of time so I can't change it. Without boring you on the details this is what I need to do:

1. I get a list of rows from a table (FOO)
2. For each FOO I need to get FOO.getBar() but it can't be in the initial query.

Basically, if Bar was a collection my problems would be solved with a collection loader for it. However, I can't see anything like that for a simple Many-to-one association!

Any thoughts on what I can do? This is driving me nuts. I'm almost at the stage where I need to break away from Hibernate to do this.

Just for re-iteration:

1. I need a list of FOO and only FOO to start.
2. For each FOO I need to fetch it's associated BAR but a very eagerly fetched BAR...


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 16, 2008 8:59 pm 
Newbie

Joined: Tue Dec 16, 2008 8:47 pm
Posts: 3
I didn't clarify very well that I don't just want the fetched BAR.

The query to grab bar is going to fetch join a pile of other stuff in a query like:

select {bar.*}, {baz.*}, {faz.*} from Bar fetch join baz fetch join faz


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 16, 2008 9:03 pm 
Newbie

Joined: Tue Dec 16, 2008 8:47 pm
Posts: 3
sheesh I'm really not making any sense with this post.

For lack of proper vocabulary to describe my problem this is the best way I can explain it:

currently, I have a few custom loaders for loading collections.

<set name="chargeImpacts" inverse="true">
<key>
<column name="LTB_DISTRICT_CD" />
<column name="TITLE_NMBR" />
</key>
<one-to-many class="ca.ltsa.srs.database.entity.ChargeImpact" />
<loader query-ref="loadChargeImpacts" />
</set>
...
<sql-query name="loadChargeImpacts">
<load-collection alias="chimp" role="ca.ltsa.srs.database.entity.Title.chargeImpacts"></load-collection>
<return-join alias="charge" property="chimp.charge"></return-join>
<return-join alias="chrgdoc" property="charge.dcmnt"></return-join>
<return-join alias="rlsdoc" property="chimp.releasedByDcmnt"></return-join>
select
{chimp.*}, {charge.*}, {chrgdoc.*}, {rlsdoc.*}
from VCHIMP as chimp
inner join VCHARG as charge
on chimp.DCMNT_DISTRICT_CD=charge.DCMNT_DISTRICT_CD
and chimp.CHARGE_NMBR=charge.CHARGE_NMBR
inner join VDCMNT as chrgdoc
on charge.DCMNT_MSTR_NMBR=chrgdoc.DCMNT_MSTR_NMBR
and charge.DCMNT_DISTRICT_CD=chrgdoc.DCMNT_DISTRICT_CD
left outer join VDCMNT as rlsdoc
on chimp.RLS_DCMNT_MSTR_NO=rlsdoc.DCMNT_MSTR_NMBR
and chimp.RLS_DCMNT_DIST_CD=rlsdoc.DCMNT_DISTRICT_CD
where
chimp.LTB_DISTRICT_CD=?
and chimp.TITLE_NMBR=?
</sql-query>






I need to do the same thing for a simple many-to-one association instead of for a collection! This is driving me crazy :(


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.