Sure,
the query is the HQL i posted. The mappings are:
<class name="Type2">
<many-to-one name="Type1" cascade="none" column="Type1id"
class="Test.Type1,Test">
</many-to-one>
<bag name="Type3List" cascade="all-delete-orphan" lazy="false"
fetch="subselect" order-by="SortOrder ASC">
<key>
<column name="Type2Id" not-null="1"></column>
</key>
<one-to-many class="Test.IType3, Test"></one-to-many>
</bag>
</class>
<class name="IType3">
<many-to-one name="Type4" column="Type4Id" class="Test.Type4,Test"
not-null="true"></many-to-one>
<subclass name="Type3" discriminator-value="DateTime">
<property name="FieldValue" column="FieldValueDateTime"
type="System.DateTime"></property>
</subclass>
</class>
Best regards,
Morten Haug
On 1 Apr, 10:49, Kenneth Siewers Møller <[email protected]>
wrote:
> Could you please post an example of your mapping and query?
>
> 2009/4/1 Morten Haug <[email protected]>
>
>
>
>
>
> > Hi Roger, thanks for replying.
>
> > Just some more explanation. Type3 has no object reference to Type2,
> > there's just a bag of Type3's with a reference to a column (Type3 can
> > have other Type-parents). I'm not sure if it has anything to do with
> > error I'm getting though, which is:
>
> > When I use this HQL:
>
> > "from Type2 a inner join fetch a.Type3List where a.Type1=:type1id"
>
> > I get a "NHibernate.LazyInitializationException: failed to lazily
> > initialize a collection, no session or session was closed" when it
> > tries to set the Type3List. And the session is definitively open.
>
> > Using similiar approach with ICriteria yields the same results.
>
> > Best regards,
> > Morten Haug
>
> > On 1 Apr, 09:53, Roger Kratz <[email protected]> wrote:
> > > Either by using three different selects,
> > > [get type3 where xxx]
> > > [get type2 where xxx]
> > > [get type1 where xxx]
> > > ...preferable batching these queries using MultiCriteria/Query
>
> > > ...or...
> > > Getting a wider set back, using joins.
> > > SetFetchMode("Reference", FetchMode.Join), Criteria
> > > join fetch, HQL
>
> > > /Roger
>
> > > -----Original Message-----
> > > From: [email protected] [mailto:[email protected]] On
> > Behalf Of Morten Haug
> > > Sent: den 1 april 2009 08:42
> > > To: nhusers
> > > Subject: [nhusers] How to eager load a object hierarchy in one batch
>
> > > Hi, lets say I have a structure like this:
>
> > > Type1
> > > |--Type2
> > > | |--Type3
> > > | |--Type3
> > > |--Type2
> > > | |--Type3
> > > | |--Type3
>
> > > How could I best fetch this tree (no lazy loading)? "Out of the box"
> > > it looks like it for each of the Type2's, it makes a select for its
> > > collection of Type3's. What I'd like is to batch it up into one select
> > > for all Type3's, and map them correctly into their respective Type2
> > > parent.
>
> > > Best regards,
> > > Morten Haug– Skjul sitert tekst –
>
> > > – Vis sitert tekst –– Skjul sitert tekst –
>
> – Vis sitert tekst –
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"nhusers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nhusers?hl=en
-~----------~----~----~----~------~----~------~--~---