Hello,
I am doing all what is right, to my knowledge, but it seems that there is some problem in saving concerning cascades (1.2.1GA)
This test
Code:
public void ShouldPersistOrderWithoutExplicitlyCallingSaveOnOrder()
{
User u = new User();
Order o = new Order();
u.AddOrder(o); // bidirectional, so this takes care of giving o to
u and u to o
Factory.GetUserDao().SaveOrUpdate(u); // <-- exception thrown here
}
throws a NHibernate.PropertyValueException
Message:not-null property references a null or transient value: Client.Businesslayer.Order.User
Source:NHibernate
PersistentClass:Client.Businesslayer.Order
PropertyName:User
TargetSite:Void CheckNullability(System.Object[], NHibernate.Persister.Entity.IEntityPersister, Boolean)
StackTrace:
at NHibernate.Impl.SessionImpl.CheckNullability(Object[] values, IEntityPersister persister, Boolean isUpdate) in C:\Users\Jan\Documents\Visual Studio 2005\Projects\Library and Components\NHibernate\1.2.1.GA\NHibernate-1.2.1.GA-src\src\NHibernate\Impl\SessionImpl.cs:line 1406
at NHibernate.Impl.SessionImpl.DoSave(Object theObj, EntityKey key, IEntityPersister persister, Boolean replicate, Boolean useIdentityColumn, CascadingAction cascadeAction, Object anything) in C:\Users\Jan\Documents\Visual Studio 2005\Projects\Library and Components\NHibernate\1.2.1.GA\NHibernate-1.2.1.GA-src\src\NHibernate\Impl\SessionImpl.cs:line 954
at NHibernate.Impl.SessionImpl.DoSave(Object obj, Object id, IEntityPersister persister, Boolean useIdentityColumn, CascadingAction cascadeAction, Object anything) in C:\Users\Jan\Documents\Visual Studio 2005\Projects\Library and Components\NHibernate\1.2.1.GA\NHibernate-1.2.1.GA-src\src\NHibernate\Impl\SessionImpl.cs:line 872
at NHibernate.Impl.SessionImpl.SaveWithGeneratedIdentifier(Object obj, CascadingAction action, Object anything) in C:\Users\Jan\Documents\Visual Studio 2005\Projects\Library and Components\NHibernate\1.2.1.GA\NHibernate-1.2.1.GA-src\src\NHibernate\Impl\SessionImpl.cs:line 767
at NHibernate.Impl.SessionImpl.Save(Object obj) in C:\Users\Jan\Documents\Visual Studio 2005\Projects\Library and Components\NHibernate\1.2.1.GA\NHibernate-1.2.1.GA-src\src\NHibernate\Impl\SessionImpl.cs:line 708
at NHibernate.Impl.SessionImpl.SaveOrUpdate(Object obj) in C:\Users\Jan\Documents\Visual Studio 2005\Projects\Library and Components\NHibernate\1.2.1.GA\NHibernate-1.2.1.GA-src\src\NHibernate\Impl\SessionImpl.cs:line 1543
at NHibernate.Engine.Cascades.CascadingAction.ActionSaveUpdateClass.Cascade(ISessionImplementor session, Object child, Object anything) in C:\Users\Jan\Documents\Visual Studio 2005\Projects\Library and Components\NHibernate\1.2.1.GA\NHibernate-1.2.1.GA-src\src\NHibernate\Engine\Cascades.cs:line 172
at NHibernate.Engine.Cascades.Cascade(ISessionImplementor session, Object child, IType type, CascadingAction action, CascadeStyle style, CascadePoint cascadeTo, Object anything) in C:\Users\Jan\Documents\Visual Studio 2005\Projects\Library and Components\NHibernate\1.2.1.GA\NHibernate-1.2.1.GA-src\src\NHibernate\Engine\Cascades.cs:line 562
at NHibernate.Engine.Cascades.CascadeCollection(CascadingAction action, CascadeStyle style, CollectionType collectionType, IType elemType, Object child, CascadePoint cascadeVia, ISessionImplementor session, Object anything) in C:\Users\Jan\Documents\Visual Studio 2005\Projects\Library and Components\NHibernate\1.2.1.GA\NHibernate-1.2.1.GA-src\src\NHibernate\Engine\Cascades.cs:line 682
at NHibernate.Engine.Cascades.Cascade(ISessionImplementor session, Object child, IType type, CascadingAction action, CascadeStyle style, CascadePoint cascadeTo, Object anything) in C:\Users\Jan\Documents\Visual Studio 2005\Projects\Library and Components\NHibernate\1.2.1.GA\NHibernate-1.2.1.GA-src\src\NHibernate\Engine\Cascades.cs:line 582
at NHibernate.Engine.Cascades.Cascade(ISessionImplementor session, IEntityPersister persister, Object parent, CascadingAction action, CascadePoint cascadeTo, Object anything) in C:\Users\Jan\Documents\Visual Studio 2005\Projects\Library and Components\NHibernate\1.2.1.GA\NHibernate-1.2.1.GA-src\src\NHibernate\Engine\Cascades.cs:line 643
at NHibernate.Engine.Cascades.Cascade(ISessionImplementor session, IEntityPersister persister, Object parent, CascadingAction action, CascadePoint cascadeTo) in C:\Users\Jan\Documents\Visual Studio 2005\Projects\Library and Components\NHibernate\1.2.1.GA\NHibernate-1.2.1.GA-src\src\NHibernate\Engine\Cascades.cs:line 615
at NHibernate.Impl.SessionImpl.PreFlushEntities() in C:\Users\Jan\Documents\Visual Studio 2005\Projects\Library and Components\NHibernate\1.2.1.GA\NHibernate-1.2.1.GA-src\src\NHibernate\Impl\SessionImpl.cs:line 3606
at NHibernate.Impl.SessionImpl.FlushEverything() in C:\Users\Jan\Documents\Visual Studio 2005\Projects\Library and Components\NHibernate\1.2.1.GA\NHibernate-1.2.1.GA-src\src\NHibernate\Impl\SessionImpl.cs:line 3067
at NHibernate.Impl.SessionImpl.AutoFlushIfRequired(ISet querySpaces) in C:\Users\Jan\Documents\Visual Studio 2005\Projects\Library and Components\NHibernate\1.2.1.GA\NHibernate-1.2.1.GA-src\src\NHibernate\Impl\SessionImpl.cs:line 2234
at NHibernate.Impl.SessionImpl.Find(CriteriaImpl criteria, IList results) in C:\Users\Jan\Documents\Visual Studio 2005\Projects\Library and Components\NHibernate\1.2.1.GA\NHibernate-1.2.1.GA-src\src\NHibernate\Impl\SessionImpl.cs:line 4950
at NHibernate.Impl.SessionImpl.Find(CriteriaImpl criteria) in C:\Users\Jan\Documents\Visual Studio 2005\Projects\Library and Components\NHibernate\1.2.1.GA\NHibernate-1.2.1.GA-src\src\NHibernate\Impl\SessionImpl.cs:line 4906
at NHibernate.Impl.CriteriaImpl.List() in C:\Users\Jan\Documents\Visual Studio 2005\Projects\Library and Components\NHibernate\1.2.1.GA\NHibernate-1.2.1.GA-src\src\NHibernate\Impl\CriteriaImpl.cs:line 312
at NHibernate.Impl.CriteriaImpl.UniqueResult() in C:\Users\Jan\Documents\Visual Studio 2005\Projects\Library and Components\NHibernate\1.2.1.GA\NHibernate-1.2.1.GA-src\src\NHibernate\Impl\CriteriaImpl.cs:line 437
at Client.Data.UserDao.GetByEmail(String email) in C:\Users\Jan\Documents\Projects\Client\Sources\branches\1.5\Client.Data\UserDao.cs:line 20
at Client.Tests.Data.TestOrderDao.DeleteUser() in C:\Users\Jan\Documents\Projects\Client\Sources\branches\1.5\Client.Tests\Data\TestOrderDao.cs:line 45
at Client.Tests.Data.TestOrderDao.ShouldPersistAddressWithoutExplicitlyCallingSaveOnAddress() in C:\Users\Jan\Documents\Projects\Client\Sources\branches\1.5\Client.Tests\Data\TestOrderDao.cs:line 38
Code:
User.AddOrder(Order) is like that:
public virtual void AddOrder(Order o)
{
if (orders == null)
orders = new List<Order>();
orders.Add(o);
o.User = this;
}
Mappings:
Code:
<class name="User"
table="[User]"
lazy="true">
<id name="Id"
column="UserID">
<generator class="identity" />
</id>
<bag name="Orders"
table="Orders"
cascade="save-update"
inverse="true">
<key column="UserID"/>
<one-to-many class="Order"/>
</bag>
</class>
<class name="Order"
table="Orders"
lazy="true">
<id name="Id"
column="OrderID">
<generator class="identity" />
</id>
<many-to-one name="User"
column="UserID"
not-null="true"
class="User"
cascade="save-update" />
</class>
What is weird is, that the User is actually persisted, so he cannot be transient eihter, at the moment, when the order is persisted.
The order's user of course is not null either.
I am completely lost,
anybody could give me a hand?
Jan