Hi,
thanks for your help. Actually the entities mentioned are about five
relation apart from each other, but I could narrow it down to a simple
relation
Class1
{
int Id;
Class2 ForeignClass;
}
mapping file
<class name="Class1" table="Class1" lazy="false">
<id name="Id" column="Id" type="int">
<generator class="increment" />
</id>
<many-to-one name="Class2" cascade="none" column="Class2" not-
null="true" />
</class>
Class2
{
int Id;
IList<Class1> ForeignClass1Collection;
}
mapping file
<class name="Class2" table="Class2" lazy="false">
<id name="Id" column="Id" type="int">
<generator class="increment" />
</id>
<bag name="ForeignClass1Collection" inverse="true" lazy="true"
cascade="all">
<key column="Class2" />
<one-to-many class="Class1" />
</bag>
</class>
now I create a transient object of class1 and add it to the
ForeignClass1Collection in Class2
Class2 persistentClass2 = session.Get<Class2>(class2Id);
Class1 class1 = new Class1(0, persistentClass2);
persistentClass2.ForeignClass1Collection.Add(class1)
thats about the standard way how I work with my entities.
class1 is transient and not yet saved. When I do now the following I
run into trouble (class1 is automatically persisted):
trans = session.BeginTransaction();
ICriteria query = session.CreateCriteria(typeof(Class2));
items = query.List<T>();
trans.Commit();
thinking about your comments, fabio, I first thought it would be
enough to set the mapping in Class2 to:
...
<bag name="ForeignClass1Collection" inverse="true" lazy="true"
cascade="save-update">
...
but same symptoms
setting it to:
...
<bag name="ForeignClass1Collection" inverse="true" lazy="true"
cascade="none">
...
will cause an exception:
NHibernate.PropertyValueException - Message="not-null property
references a null or transient ...
What are the possible options to solve the problem?
Thank you antoschka
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"nhusers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nhusers?hl=en
-~----------~----~----~----~------~----~------~--~---