-->
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: SQLQuery, lazy/eager fetch modes
PostPosted: Mon Oct 03, 2011 12:13 pm 
Newbie

Joined: Thu Jul 21, 2011 11:41 am
Posts: 5
I have a SQL statement that I'm using as a basis for a SQL Query. The base entity mapped returns it no problem. The base entity has 3 bags - which are mapped to other objects using their foreign keys.

The issue I'm having is that I want to return deeper sets of objects based on a runtime parameter, and I can't seem to set any fetch mode parameters for SQL Query.

In essence, I need to at runtime be able to either load all the child records or omit them from my final object.

I've partially solved the problem in a "hackish" way by adding a filter that will pass "1 = 2" to the query loading the bag when the filter is enabled:

Code:
<bag ..>
  ...
  <filter name="no-children" condition="1 = 2"/>
</bag>


Not happy with it, but I wasn't able to find another way. (If there is a better way please let me know; I wasn't able to find a way too set a depth value or anything to zero to not load child elements, or to just tell the SQLQuery object not to load children or specific properties).

The issue is that for this object to be usable after the Hibernate session is closed I need to force eager loading. I don't want to change the "default" to not lazy in the mapping XML if I don't have to; I want to say "for this SQL query load with a fetch mode of EAGER". Or if I have to specifically define which bag properties I want to load "eager".


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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.