I have a class that contains a set of ordered products. The set is ordered by a column 'Order' in my table and the order column does not allow nulls. When I persist this class, I get an error: cannot insert NULL into column 'Order.'
So the problem is that the Order column is not mapping when i persist but the set of products is being ordered correctly. what is the proper way of doing this?
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0"
namespace="Com.WildTangent.ProductCatalog.Data"
assembly="ProductCatalog">
<class name="RuleGroupSlot" table="t_RuleGroupSlot">
<cache usage="read-write" />
<id name="Id" column="RuleGroupSlotId" type="int">
<generator class="native" />
</id>
<set name="OrderedProducts" table="t_ProductSlotOrder" order-by="[Order]">
<key column="RuleGroupSlotId" />
<many-to-many column="ProductId" class="Product" />
</set>
</class>
</hibernate-mapping>
Code:
public class RuleGroupSlot
{
public virtual int Id
{
get { return _id; }
set { _id = value; }
}
// We don't have backward references to RuleGroup and Slot here for efficiency reasons
public IProductList GetOrderedProducts()
{
ProductList productList = new ProductList();
productList.Products = CollectionsUtil.ToGenericList<Product>(OrderedProducts);
return productList;
}
public virtual ISet OrderedProducts
{
get { return _orderedProducts; }
set { _orderedProducts = value; }
}
private int _id;
private ISet _orderedProducts;
}
[/code]