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: Too many results using CollectionFetchMode.Join (sometimes)
PostPosted: Wed Apr 23, 2008 5:59 am 
Newbie

Joined: Wed Apr 23, 2008 5:50 am
Posts: 1
Hi,

I'm using nhibernate 1.2.0 with syscache

I have three objects A, B and C. Between A and B there is a one-to-many relationship. Between B and C there is a many-to-many relationship.

The objects A, B and C al use te READ-WRITE cache

The mapping from A to B looks like this:

Code:
[Bag(0, Name = "B", Lazy = true, Fetch = CollectionFetchMode.Join, Cascade = CascadeStyle.All, Inverse = false)]
[Key(1, Column = "a_id")]
[OneToMany(2, ClassType = typeof(B))]
public IList B
{
   get { return b; }
   set { b = value; }
}


The mapping from B to C looks like this:

Code:
[Bag(0, Name = "C", Lazy = false, Cascade = CascadeStyle.SaveUpdate, Inverse = false, Table = "B_C", Fetch = CollectionFetchMode.Join)]
[Key(1, Column = "b_id")]
[ManyToMany(2, ClassType = typeof(C), Column = "c_id")]
public IList C
{
   get { return c; }
   set { c = value; }
}


The problem is like this:

When executing the code:

Code:
IQuery query = session.CreateQuery("SELECT a FROM " + typeof(A) + " a WHERE a.id = :id");
query.SetInt64("id", id);
A a = (A)query.UniqueResult();


One object of type A is returned. It has a reference to three objects B (B1, B2 and B3). B1 has a relationship with three C objects C1, C2 and C3.
B2 has a relationship with three C objects C4, C5, C6. B3 has a relationship with one C objcte C7.

So usually when I execute the query the following structure is returned:
Code:
A
|--B1
|   |-C1
|   |-C2
|   |-C3
|
|--B2
|   |-C4
|   |-C5
|   |-C6
|
|--B3
|   |-C7

But sometimes when I do exactly the same query this structure is returned:

Code:
A
|--B1
|   |-C1
|   |-C2
|   |-C3
|
|--B1
|   |-C1
|   |-C2
|   |-C3
|
|--B1
|   |-C1
|   |-C2
|   |-C3
|
|--B2
|   |-C4
|   |-C5
|   |-C6
|
|--B2
|   |-C4
|   |-C5
|   |-C6
|
|--B2
|   |-C4
|   |-C5
|   |-C6
|
|--B3
|   |-C7


Suddenly A does not have three B objects but 7, the total number of C objects related to the B objects related to C.

When I remove the Fetch = CollectionFetchMode.Join in the A to B mapping the problem seems to be solved. I was trying to reduce the number of selects when I put this in, is this normal behaviour of the CollectionFetchMode.Join? And if so, why doesn't it give the same structure every time?

Thnx,

Sander


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.