-->
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.  [ 4 posts ] 
Author Message
 Post subject: PersistentGenericBag is read only?
PostPosted: Fri Dec 28, 2007 1:57 pm 
Newbie

Joined: Tue Feb 20, 2007 11:36 pm
Posts: 8
Location: Austin TX, USA
I'm porting an app from Ayende's Generics and 1.0.3 to pure 1.2 (so removing Ayende's Generics) and am running into an issue I can't find documentation on.. (based on the few blogs that talk about this kind of porting.

I keep getting the following exception when I run my "add" routines.

System.NotSupportedException : Collection is read-only.
at System.ThrowHelper.ThrowNotSupportedException(ExceptionResource resource)
at System.Collections.ObjectModel.ReadOnlyCollection`1.System.Collections.Generic.ICollection<T>.Add(T value)
at NHibernate.Collection.Generic.PersistentGenericBag`1.Add(T item)
C:\Projects\myProject\User.cs(174,0): at MyNameSpace.UserBase.AddOwnedNode(INode node)

Below is the add routine I am using

Code:
/**** The Add Routine ****/
public void AddOwnedNode(INode node)
        {
            if (_ownedNodes.Contains(node)) return;
            _ownedNodes.Add(node);
            if (node.Owner == null)
                node.Owner = this;
            else if (!node.Owner.Equals(this))
                node.Owner = this;
        }

/**** The property & Field ****/
private IList<INode> _ownedNodes = new List<INode>();
        public virtual IList<INode> OwnedNodes
        {
            get { return new ReadOnlyCollection<INode>(_ownedNodes); }
            set { _ownedNodes = value; }
        }

/**** The Mapping XML for this field ****/
    <bag name="OwnedNodes" lazy ="true" inverse ="true"   >
      <key column="OwnerUserFk"/>
      <one-to-many class ="MyNameSpace.INode, MyNameSpace.Interfaces"/>
    </bag>

/**** The mapping for the other side (node.Owner) ****/
<many-to-one name="Owner" class="MyNameSpace.IUser, MyNameSpace.Interfaces" column ="OwnerUserFk" not-null="true" />


Notes: I am using Interfaces and sub-classes. The technique is based on a blog post I read but goes like this

Code:
<class name="[My Interface Name]" >
   <!---- All class properties that have setters in the interface ---->
   <subclass name="[My Class Implientation name]" discriminator-value="something">
   <!---- My class properties that don't have setters in the interface ---->
   </subclass>
</class>


BUT I'm not thinking that this is related to my issue. As the maps are compiling and working fine..

Am I being stupid (My guess is yes) and PersistentGenericBag is read-only.. or am I missing something?

Thanks in advance fo the help.

Josh

_________________
Josh Handel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 31, 2007 1:23 pm 
Newbie

Joined: Tue Feb 20, 2007 11:36 pm
Posts: 8
Location: Austin TX, USA
I realized my 1.2 dll was a little old (1.2.0) so I downloaded 1.2.1 GA BUT no luck.. my collections are still claiming to be read only.. I'm not sure whats up as my mappings (excluding my subclassing) look the same as Billy McCafferty's mappings as do my Add and Remove functions..

So anyone know why my generic collections using Default 1.2.1 nhibernate are acting all "read-only" on me?

Thanks
Josh

_________________
Josh Handel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 31, 2007 3:32 pm 
Newbie

Joined: Tue Feb 20, 2007 11:36 pm
Posts: 8
Location: Austin TX, USA
Given enough time you will answer your own questions..

So this is what I have figured out..

NHibernate is getting my read only collection from my getter property while it is saving and/or loading the object. it then takes that read only version of my collection, wraps it in the persistantgenericbag and stuffs it back into my setter. The result is my collection becomes read only.

given that I got this methodology off of Billy McCafferty, I'm not sure how his collections don't throw the same error?

Josh

_________________
Josh Handel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 02, 2008 3:24 pm 
Beginner
Beginner

Joined: Fri Sep 02, 2005 12:13 pm
Posts: 44
Location: Denver, CO
Hi Josh,

I've released a couple of posts concerning custom collections with the latest NHibernate. I believe the new approach is much simpler than the advice I gave in my codeproject.com article.

The first in the three-part series can be found at:

http://devlicio.us/blogs/billy_mccaffer ... asics.aspx

Billy McCafferty


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.