-->
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: Querying Child Entity into Existing Collection
PostPosted: Sat Aug 27, 2005 2:33 am 
Newbie

Joined: Thu Aug 04, 2005 9:35 am
Posts: 4
Hi Folks,

Got a question abouut retrieving a child and adding it to an existing parent's child collection (specifically if its possible).

For example: Blog is a parent, BlogEntry is a child of Blog. Blog has a BlogEntries bag (IList).

The BlogEntries bad is lazy loaded.

Situation:
a Blog is retrieved from the database. The BlogEntries are not retireved (as the collection is lazy loaded).

I want to retrieve a specific BlogEntry and get it into the Blog's BlogEntries list.

Can this be done? How can this be done?

-s


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 29, 2005 5:39 am 
Regular
Regular

Joined: Mon Jul 18, 2005 4:10 am
Posts: 92
Location: Poland
Hi,

Retrieving children into persistent collection is transparent in NHibernate (even if lazy loaded). Just access your lazy loaded list and it will be automaticly initialized, if only you have the Session open between fetching the parent object and accessing collection.
I don't think you can get "specific" child with such design, if you need it I suggest replacing BlogEntries bag with a method e.g. "BlogEntry getEntryById(int id) ..." and doing a Session.Load(...) there.

_________________
michal


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 29, 2005 6:26 pm 
Newbie

Joined: Thu Aug 04, 2005 9:35 am
Posts: 4
That's kinda what I figured :(

I'm kinda stuck on a Domain-Driven Design problem where I only want to get BlogEntry instances through the Blog.

In my case, I have an existing Blog instance that was retrieved from NH. It's lazy-loaded blog entries list is already assigned an NH bag, so arbitrarilly adding to it isn't an option since I'm not looking for save or update behavior on teh BlogEntry instances in the collection.

I think I can make this work if I evict the Blog entity, retrieve the BlogEntry, and add it to the list.

Cheers,
Scott


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.