-->
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: Half-lazy collection mappings; read-only class mappings
PostPosted: Thu Jun 09, 2005 11:59 pm 
Senior
Senior

Joined: Thu May 12, 2005 11:40 pm
Posts: 125
Location: Canada
Hibernate version: 3.0.5

I have two classes, A and B, which have a many-to-many relationship to each other on a join table. They are mapped and work fine. The relationship is mapped lazily, so when I call A.getBs() and iterate over the resulting collection, I get n+1 selects. I get the impression that this is the expected behaviour from the FAQ, which suggests I map the association eagerly.

This is not what I want however. An eager mapping implies that when A is loaded, all its Bs should be loaded at that same time. Instead, I want an A's Bs to remain unloaded until I actually call A.getBs(), at which point the entire collection and all the objects within it should be initialized. I tried calling Hibernate.initialize() on the collection, but that doesn't initialize the objects inside it. I can emulate the behaviour by using batch fetching and setting the batch fetch size to a large number (like say 1000), but then that's not perfect either. Hibernate generates SQL that uses the 'wrong' side of the association table resulting in hundreds of ?, ?, ?, ?... for each and every row being batch fetched. It makes sense in the context of batch fetching of course, but if I know that I will need the whole collection, I'd like to be able to avoid this.

On an unrelated note, is it possible to declare certain mapped classes as 'read only' and have Hibernate enforce their non-persistability?


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.