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.  [ 3 posts ] 
Author Message
 Post subject: Save System.Collections.Generic.IList<> - NHibernate 1
PostPosted: Tue Jul 04, 2006 9:09 pm 
Newbie

Joined: Tue Jul 04, 2006 8:56 pm
Posts: 4
Hi, i get the "Could not save object" message when persist the class Pessoa.
My code:

public class Area
{
private int m_ID;
private string m_Nome;

public virtual int ID
{
get
{
return m_ID;
}
set
{
m_ID = value;
}
}

public virtual string Nome
{
get
{
return m_Nome;
}
set
{
m_Nome = value;
}
}
}

public class Pessoa
{
private int m_ID;
private string m_Nome;
private Cidade m_Cidade;
private IList<Area> m_Areas;

public virtual int ID
{
get
{
return m_ID;
}
set
{
m_ID = value;
}
}

public virtual string Nome
{
get
{
return m_Nome;
}
set
{
m_Nome = value;
}
}

public virtual Cidade Cidade
{
get
{
return m_Cidade;
}
set
{
m_Cidade = value;
}
}

public virtual IList<Area> Areas
{
get
{
if (m_Areas == null)
m_Areas = new List<Area>();

return m_Areas;
}
set
{
m_Areas = value;
}
}
}

My Mapping File:

<class name="Area" table="Area">
<id name="ID" column="ID" type="Int32">
<generator class="identity"/>
</id>

<property name="Nome" column="Nome" type="String" not-null="true"/>
</class>

<class name="Pessoa" table="Pessoa">
<id name="ID" column="ID" type="Int32">
<generator class="identity"/>
</id>

<property name="Nome" column="Nome" type="String" not-null="true"/>

<many-to-one name="Cidade" class="Cidade"/>

<set name="Areas" table="PessoaArea" generic="true">
<key column="Pessoa"/>
<many-to-many class="Area" column="Area"/>
</set>
</class>

My Dao Code:
session.save(objPessoa);

I get the error "Could not save object".
InnerException:
{"Unable to cast object of type 'System.Collections.Generic.List`1[MorpheusTest_Model.Area]' to type 'Iesi.Collections.Generic.ISet`1[MorpheusTest_Model.Area]'."}

Do you have any idea?

Thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 04, 2006 10:15 pm 
Regular
Regular

Joined: Wed Jun 21, 2006 3:13 pm
Posts: 110
I think the issue is simply that you've defined it as a <set in your mapping but an IList in your code. Change it from <set to <bag.

Or, implement ISet<T> instead of IList<T>.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 04, 2006 10:30 pm 
Newbie

Joined: Tue Jul 04, 2006 8:56 pm
Posts: 4
Thank you!!!
I change the mapping to <bag> and it's work!!


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