I received a could not save object exception and the InnerException is :
Unable to cast object of type 'System.Collections.ArrayList' to type 'Iesi.Collections.ISet'
Summary of the two classes :
Code:
public class Product
{
private int id;
private String name;
private ArrayList releases; //I also try an ISet but with the same class cast exception
// + properties
}
public class ProductRelease
{
private int id;
private String name;
private DateTime released;
private Product product;
}
So a product can have more than one release.
The mapping files :
Code:
<?xml version="1.0"?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="sgub.ProductRelease, sgub" table="productrelease">
<id name="Id" column="id" >
<generator class="native" />
</id>
<property name="Name" column= "name" type="String" length="45" />
<property name="Released" column= "productreleased" type="Date" />
<many-to-one name="Product" column="productid" not-null="true" />
</class>
</hibernate-mapping>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="sgub.Product, sgub" table="product">
<id name="Id" column="id" >
<generator class="native" />
</id>
<property name="Name" column= "name" type="String" length="45"/>
<set name="Releases" inverse="true">
<key column="id" />
<one-to-many class="sgub.ProductRelease, sgub" />
</set>
</class>
</hibernate-mapping>
And the way I save the objects
Code:
Product nutella=new Product();
nutella.Name="Nutella";
ProductRelease alpha=new ProductRelease();
alpha.Name="alpha";
alpha.Released=DateTime.Now;
nutella.Releases.Add(alpha);
alpha.Product=nutella;
session =factory.OpenSession();
transaction = session.BeginTransaction();
session.Save(nutella);
session.Flush();
transaction.Commit();