Hi again,
A new problem came up:
after using <set> instead of <bag> I can't save an order:
Code:
Code:
Order order = new Order();
order.Price = 100.0;
ISession session = sessionFactory.OpenSession();
session.Save(order);
session.Close();
Exception:Quote:
Could not save object
Specified cast is not valid.
at NHibernate.Type.SetType.Wrap(ISessionImplementor session, Object collection)
at NHibernate.Impl.WrapVisitor.ProcessArrayOrNewCollection(Object collection, PersistentCollectionType collectionType)
at NHibernate.Impl.WrapVisitor.ProcessCollection(Object collection, PersistentCollectionType collectionType)
at NHibernate.Impl.AbstractVisitor.ProcessValue(Object value, IType type)
at NHibernate.Impl.WrapVisitor.ProcessValues(Object[] values, IType[] types)
at NHibernate.Impl.SessionImpl.DoSave(Object theObj, Key key, IClassPersister persister, Boolean replicate, Boolean useIdentityColumn, CascadingAction cascadeAction, Object anything)
at NHibernate.Impl.SessionImpl.DoSave(Object obj, Object id, IClassPersister persister, Boolean useIdentityColumn, CascadingAction cascadeAction, Object anything)
at NHibernate.Impl.SessionImpl.SaveWithGeneratedIdentifier(Object obj, CascadingAction action, Object anything)
Using <bag> instead of <set> in order mapping (see below) works fine but when creating the DB using SchemaExport, the relation table rOrderToUser is created without the desired PK (UserID + OrderID).
Any ideas regarding the cast exception?
Ruby
Order Mapping:Code:
<class name="TestNameSpace.Order, impl" table="tOrder">
<id name="Id" type="Int32" column="ID">
<generator class="assigned" />
</id>
<property name="Price" column="Price" type="Double" />
<set name="Users" table="rOrderToUser" inverse="false">
<key column="OrderID" />
<many-to-many column="UserID" class="TestNameSpace.User, impl" />
</set>
</class>
User Mapping:Code:
<class name="TestNameSpace.User, impl" table="tUser">
<id name="Id" type="Int32" column="ID">
<generator class="assigned" />
</id>
<property name="Name" column="Name" type="String" />
</class>
[/code]