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.  [ 16 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Trouble with adding child record
PostPosted: Tue Apr 01, 2008 8:57 am 
Newbie

Joined: Mon May 21, 2007 3:14 pm
Posts: 14
I am attempting to add a child record to an Oracle database using NHibernate in C#. I added a function to my Parent class called "AddChild" that looks like this:

public void AddChild(Child c)
{
c.Child = this;
this.Children.Add(c);
}

On the line that says "this.Children.Add(c)", I get the following exception:
NotSupportedException was unhandled: Collection was of a fixed size.

How can I set the collection to not have a fixed size?

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 01, 2008 9:04 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
Can you post the declaration of Children ? What kind of collection do you use ?

_________________
--Wolfgang


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 01, 2008 9:42 am 
Newbie

Joined: Mon May 21, 2007 3:14 pm
Posts: 14
private IList mChildren = new ArrayList();

public virtual System.Collections.IList Children
{
get
{
return mChildren;
}
set
{
mChildren = value;
}
}


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 01, 2008 10:08 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
ArrayList should't be fixed size per default. When you get the exception, are you working on a persisted object (loaded with hibernate) and is Children or mChidlren part of the mapping ?

_________________
--Wolfgang


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 01, 2008 10:14 am 
Newbie

Joined: Mon May 21, 2007 3:14 pm
Posts: 14
Yes, I am working on a persisted object loaded with nhibernate. I first retrieve the parent object, then I am calling the AddChildren function from that object.

Children is indeed part of the mapping, here is what the mapping looks like:

<bag name="Children" inverse="true" lazy="false">
<key column="Parent_Id" />
<one-to-many class="Template.Domain.Child, Template.Domain" />
</bag>

I appreciate you working through this with me. Let me know if you need any additional information.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 01, 2008 10:24 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
Currently I have no real idea. Can you post the mappings of parent and child and the code you use for loading the object ?

_________________
--Wolfgang


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 01, 2008 11:08 am 
Newbie

Joined: Mon May 21, 2007 3:14 pm
Posts: 14
Okay from now on I will use the actual class names for parent and child. Parent is "ApplicationCntl" and Child is "ApplicationCntlDtl". I kept those generic in my last few posts to make it easier to read.

Here is the mapping for the parent:

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" default-lazy="false" default-cascade="save-update">
<class name="Template.Domain.ApplicationCntl, Template.Domain" table="Application_Cntl">
<id name="Id" type="Int32" column="Application_Cntl_Id">
<generator class="identity" />
</id>
<property name="ApplicationCntlCd" column="Application_Cntl_Cd" type="String" />
<property name="ApplicationCntlDesc" column="Application_Cntl_Desc" type="String" />
<bag name="ApplicationCntlDtls" inverse="true" lazy="false">
<key column="Application_Cntl_Id" />
<one-to-many class="Template.Domain.ApplicationCntlDtl, Template.Domain" />
</bag>
<bag name="ApplicationCntlDtlsIListLazyFalse" inverse="true" lazy="false">
<key column="Application_Cntl_Id" />
<one-to-many class="Template.Domain.ApplicationCntlDtl, Template.Domain" />
</bag>
<bag name="ApplicationCntlDtlsIListLazyTrue" inverse="true" lazy="true">
<key column="Application_Cntl_Id" />
<one-to-many class="Template.Domain.ApplicationCntlDtl, Template.Domain" />
</bag>
<property name="CreateDate" column="Create_Date" type="DateTime" />
<property name="UpdateDate" column="Update_Date" type="DateTime" />
<property name="UpdateSource" column="Update_Source" type="String" />
</class>
</hibernate-mapping>

Here is the mapping for the child:

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" default-lazy="false" default-cascade="save-update">
<class name="Template.Domain.ApplicationCntlDtl, Template.Domain" table="Application_Cntl_Dtl">
<id name="Id" type="Int32" column="Application_Cntl_Dtl_Id">
<generator class="identity" />
</id>
<many-to-one name="ApplicationCntl" column="Application_Cntl_Id" class="Template.Domain.ApplicationCntl, Template.Domain" />
<property name="ApplicationCntlDtlValueDesc" column="Application_Cntl_Dtl_Desc" type="String" />
<property name="CreateDate" column="Create_Date" type="DateTime" />
<property name="UpdateDate" column="Update_Date" type="DateTime" />
<property name="UpdateSource" column="Update_Source" type="String" />
</class>
</hibernate-mapping>

And here is the code I use for loading the object (note that mISession is an Nhibernate ISession object that is open, and that the bolded line is the one that errors):

ITransaction transaction = mISession.BeginTransaction();

Template.Domain.ApplicationCntl applCntl = mISession.Load("ApplicationCntl".GetType(), 2);

IQuery customQuery = mISession.CreateQuery("From ApplicationCntl");
IList<Template.Domain.ApplicationCntl> applCntlList = customQuery.List();

Template.Domain.ApplicationCntlDtl applCntlDtl = new Template.Domain.ApplicationCntlDtl();

applCntl.AddApplicationCntlDtl(applCntlDtl);
applCntlList.Add(applCntl);


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 01, 2008 12:10 pm 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
Why are you mapping the same children to three different collections in the parent object ?

Code:
<bag name="ApplicationCntlDtls" inverse="true" lazy="false">
     <key column="Application_Cntl_Id" />
     <one-to-many class="Template.Domain.ApplicationCntlDtl, Template.Domain" />
</bag>
<bag name="ApplicationCntlDtlsIListLazyFalse" inverse="true" lazy="false">
     <key column="Application_Cntl_Id" />
     <one-to-many class="Template.Domain.ApplicationCntlDtl, Template.Domain" />
</bag>
<bag name="ApplicationCntlDtlsIListLazyTrue" inverse="true" lazy="true">
     <key column="Application_Cntl_Id" />
     <one-to-many class="Template.Domain.ApplicationCntlDtl, Template.Domain" />
</bag>


Can you reduce the mapping to one collection and try again.

Is there some special code in your properties for accessing the lists (e.g. converting them to a read only collection or sth like that) ?

_________________
--Wolfgang


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 01, 2008 1:06 pm 
Newbie

Joined: Mon May 21, 2007 3:14 pm
Posts: 14
I had a few extra mapping of the same children for some testing I was doing. I removed those mappings and tried again, but no luck. As far as I am aware, there is no special code in my properties for accessing the lists.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 01, 2008 1:23 pm 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
Strange ! Can you check the actual type of applCntl.ApplicationCntlDtls after you've loaded the object and if that list is of fixed size ?

What are you doing in applCntl.AddApplicationCntlDtl(applCntlDtl) ?

_________________
--Wolfgang


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 02, 2008 9:33 am 
Newbie

Joined: Mon May 21, 2007 3:14 pm
Posts: 14
The type of applCntl.ApplicationCntlDtls after being loaded is Systems.Collections.IList {object[]} and the IsFixedSize property is true.

Here is what I am doing in applCntl.AddApplicationCntlDtl(applCntlDtl):

public virtual void AddApplicationDtl(ApplicationCntlDtl applCntlDtl)
{
applCntlDtl.ApplicationCntl = this;
ApplicationCntlDtls.Add(applCntlDtl);
}

The error occurs at ApplicationCntlDtls.Add(applCntlDtl);


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 02, 2008 9:47 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
The list shoud be something like NHibernate.Collection... can you change your mapping and class to a generic list ?

IList<Template.Domain.Child>

For me it looks like you get an plain array loaded into your class. Which hibernate version and .Net version do you use ?

_________________
--Wolfgang


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 02, 2008 11:03 am 
Newbie

Joined: Mon May 21, 2007 3:14 pm
Posts: 14
I change my ApplicationCntl class declaration of mApplicationCntlDtls from

private IList mApplicationCntlDtls = new ArrayList();

to

private IList<ApplicationCntlDtl> mApplicationCntlDtls = new List<ApplicationCntlDtl>();

Now the actual type of applCntl.ApplicationCntlDtls after I've loaded the object is System.Collections.Generic.IList<Template.Domain.ApplicationCntlDtl> {Template.Domain.ApplicationCntlDtl[]}

There is no "IsFixedSize" property on this object. I still get the error.

I am using NHibernate version 1.2.0.4 and .Net version 2.0.50727


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 03, 2008 7:06 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
Did you also change the type of the property ?

_________________
--Wolfgang


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 03, 2008 9:23 am 
Newbie

Joined: Mon May 21, 2007 3:14 pm
Posts: 14
Yes, I did.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 16 posts ]  Go to page 1, 2  Next

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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.