Hi,
My problem is that a cascading one-to-many association works fine, unless I turn on the foreign key integrity check in the DB server. Then NHibernate throws an exception, even though the foreign key it generated is totally valid. If I remove the foreign key constraint in the DB, NHibernate persists the parent and children, and the children have the correct foreign key.
I decided to try and put a many-to-one element in the target class thinking that NHibernate had to "know" about the constraint.
so the parent class (RentAssist.Claimant) now has:
<id name="Claimant_id" type="Int32" column="claimant_id">
<generator class="hilo">
<param name="table">claimant_hi_value</param>
<param name="column">next_value</param>
<param name="max_lo">0</param>
</generator>
</id>
<set name="Claimant_pets" inverse="true" cascade="all-delete-orphan" lazy="true">
<key column="pet_claimant_id"/>
<one-to-many class="Pet"/>
</set>
and the pet class has this:
<id name="Pet_id" type="Int32" column="pet_id">
<generator class="hilo">
<param name="table">pet_hi_value</param>
<param name="column">next_value</param>
<param name="max_lo">0</param>
</generator>
</id>
<property name="Pet_claimant_id" type="Int32" column="pet_claimant_id"/>
<many-to-one name="Pet_claimant_id" class="RentAssist.Claimant" column="claimant_id"/>
Now I get an exception in ISession.save {"Unknown entity class: System.Int32"}
Here's some stack:
NHibernate.Impl.SessionFactoryImpl.GetEntityPersister(Type theClass)\r\n at NHibernate.Impl.SessionImpl.GetClassPersister(Type theClass)\r\n at NHibernate.Impl.SessionImpl.GetEntityPersister(Object obj)\r\n at NHibernate.Impl.SessionImpl.IsUnsaved(Object obj, Boolean earlyInsert, Object self)\r\n at NHibernate.Impl.SessionImpl.NullifyTransientReferences(Object value, IType type, Boolean earlyInsert, Object self)\r\n at NHibernate.Impl.SessionImpl.NullifyTransientReferences(Object[] values, IType[] types, Boolean earlyInsert, Object self)\r\n at NHibernate.Impl.SessionImpl.DoSave(Object theObj, EntityKey key, IEntityPersister persister, Boolean replicate, Boolean useIdentityColumn, CascadingAction cascadeAction, Object anything)\r\n at NHibernate.Impl.SessionImpl.DoSave(Object obj, Object id, IEntityPersister persister, Boolean useIdentityColumn, CascadingAction cascadeAction, Object anything)\r\n at NHibernate.Impl.SessionImpl.SaveWithGeneratedIdentifier(Object obj, CascadingAction action, Object anything)\r\n at NHibernate.Impl.SessionImpl.Save(Object obj)\r\n at NHibernate.Impl.SessionImpl.SaveOrUpdate(Object obj)\r\n
Any help?
_________________ Fred Stann
Solutions Architect
|