Found shared references to a collection

2,265 views
Skip to first unread message

Jan Limpens

unread,
Oct 23, 2008, 2:39:02 PM10/23/08
to nhu...@googlegroups.com
hi guys,

i have a

class Foo
{
IList Categories { get; set; }
}

and

class Bar : Foo {
public Bar(Foo parent) { this.parent = parent; }
IList Categories {
get {return parent.Categories;}
set {parent.Categories = value; } }
}

when I try to hibernate this, I get a
HibernateException: Found shared references to a collection: Foo.Categories

which is true, but intended behavior. Can I somehow map around this?
--
Jan
___________________
j...@limpens.com
www.limpens.com
+55 (11) 3082-1087
+55 (11) 3097-8339

Jon Palmer

unread,
Oct 23, 2008, 2:40:37 PM10/23/08
to nhu...@googlegroups.com
Why do you have Bar subclass Foo and also compose a Foo in the parent field?

Jan Limpens

unread,
Oct 23, 2008, 2:58:34 PM10/23/08
to nhu...@googlegroups.com
Bar is ...

I have Product:Article and SubArticle:Article (among others).
SubArticles are Products that override (datawise) some properties,
like Name, Weight, Price (a SubArticle is essentially the Product in a
different quantity. If the Product comes in 50 units, there might be a
SubArticle that comes with 10 units, or 1).

So actually they do SubArticle does not inherit from Product. The fact
that I pass it a Product as a parent is likely to change soon. Right
now only Product can have SubArticles.

Jon Palmer

unread,
Oct 23, 2008, 4:26:48 PM10/23/08
to nhu...@googlegroups.com
You should really have a new keyword on the definition of the Categories in Bar or declare Categories as virtual in Foo and override in Bar.
Not sure if NHibernate deals with the first case but if defintiely handles the second.

Jan Limpens

unread,
Oct 23, 2008, 7:00:35 PM10/23/08
to nhu...@googlegroups.com
That's the problem with foobar code. It tends to oversimplify code (I
tend to :))
Categories is virtual in Article and overridden in SubArticle. Still I
get this error. I will post original code tomorrow.

Will Shaver

unread,
Oct 23, 2008, 7:03:30 PM10/23/08
to nhu...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages