-->
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: Collection is Read-Only?
PostPosted: Sun Feb 25, 2007 2:30 am 
Newbie

Joined: Tue Feb 20, 2007 11:36 pm
Posts: 8
Location: Austin TX, USA
I'm using 1.2.0 CR1 and I am getting the oddest error when I try to do an Add to any of my bags.

Code:
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)


Here is what my bag Maps look like

Code:
<bag name="LoginHistory" inverse="true" access="nosetter.camelcase-underscore" cascade="delete">
      <key column="UserFk"/>
      <one-to-many class ="UserLoginHistory"/>
    </bag >

here is what the actual property looks like..

Code:
  private IList<UserLoginHistory> _loginHistory = new List<UserLoginHistory>();

        public IList<UserLoginHistory> LoginHistory
        {
            get { return new ReadOnlyCollection<UserLoginHistory>(_loginHistory); }
        }

and here is what my add function looks like (all wrapped up so that child gets to know its parent :-)..)
Code:
   public void AddLoginHistory(UserLoginHistory history)
        {
            if (_loginHistory.Contains(history)) return;
            _loginHistory.Add(history); // < -- this is where the fails (and notice.. its the private IList not the public read only IList)
            if (history.User==null)
                history.User = this;
            else if (!history.User.Equals(this))
                history.User = this;
        }


Now I am fairly firmilar with 1.0.X NHibernate and have been using it for a while.. so I am trying to move forward to 1.2 and use generics but this just stumps me? Is it because inverse="true"? if so I am ok with that.. I just need to know how to force a refresh of my collections to reflect freshly added children.

Thanks in advance for the help :-)
Josh

_________________
Josh Handel


Top
 Profile  
 
 Post subject:
PostPosted: Sun Feb 25, 2007 3:39 am 
Senior
Senior

Joined: Mon Aug 21, 2006 9:18 am
Posts: 179
Try changing your access to access="field.camelcase-underscore".
I'm curious, is the parent lazyloaded?

_________________
If this helped...please remember to rate it!


Top
 Profile  
 
 Post subject:
PostPosted: Sun Feb 25, 2007 12:02 pm 
Newbie

Joined: Tue Feb 20, 2007 11:36 pm
Posts: 8
Location: Austin TX, USA
I tested both lazy load and not lazy load with the same result. I just tried your suggestion (field accessor) and I could add to the collection so that worked.. I wonder why the other accessor didn't work?

Thanks
Josh

_________________
Josh Handel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 26, 2007 12:13 pm 
Senior
Senior

Joined: Mon Aug 21, 2006 9:18 am
Posts: 179
I am glad at least that worked. It is odd to me, too. I am going to try to do some tests on this because I am curious also.

Take care!

_________________
If this helped...please remember to rate it!


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.