Nhibernate error when inserting an object with an one-to-one relationship to another object -


When I try to insert an object from one object into another object, then I have a problem.

Mapping file

  & lt; Hibernate-mapping xmlns = "pen: nibinet-mapping -2.2" & gt;  

& lt; Id name = "id" column = "article_id" type = "int32" not saved-value = "0" & ​​gt; & Lt; Generator class = "parent" /> & Lt; / Id & gt; & Lt; Property name = "title" column = "title" type = "string" no-null = "true" length = "255" /> & Lt; Property Name = "Body" column = "body" type = "string" length = "1073741823" /> & Lt; Property Name = "IsEnabled" column = "is_enabled" type = "boolean" not-null = "true" /> & Lt; Many-to-one name = "parent article" class = "..." column = "parent" cascade = "all" /> & Lt; Bag name = "child" lazy = "true" cascade = "all-removed-orphan" & gt; & Lt; Key column = "parent_id" /> & Lt; One-to-many classes = "..." /> & Lt; / Bag & gt;

The class follows this type of mapping file and is left for simplicity.

Then there is another class named Special Article. The mapping for this class is as follows:

  & lt; Hibernate-mapping xmlns = "vase: nibinet-mapping -2.2" & gt;  

& lt; Id name = "id" column = "id" type = "int32" not saved-value = "0" & ​​gt; & Lt; Generator class = "parent" /> & Lt; / Id & gt; & Lt; Property name = "value" column = "value" type = "double" no-null = "true" /> & Lt; One-to-one name = "paragraph" square = "..." fetch = "join" cascade = "all" />

/// Set the ID for this question /// & lt; / Summary & gt; Public Virtual Ent ID {Received; Set; } /// & lt; Summary & gt; /// Get the expected value for this question or answer /// & lt; / Summary & gt; Public virtual double value {get; Set; } /// & lt; Summary & gt; /// For the remaining information that contains the article / set /// & lt; / Summary & gt; Go to public virtual paragraph paragraph; Set; }}

When I want to insert a special article in DB i:

  // Populate some articles / some special articles / populate some code The following code is some special articles wrapped in some transactions. Article = some articles; Session.SaveOrUpdate (someArticle); Session.SaveOrUpdate (someSpecialArticle);  

The object is inserted in some articles, but the insert statement for the object is some special article: insert in TBL (value) values ​​(@ P); Choose SCOPE_IDENTITY ()

Where is article_id to specify the original text?

thx

proper mapping:

  & Lt; Many-to-one name = "article" fetch = "join" cascade = "all" unique = "true" / & gt;  

When you make one mapping from one to NHibernate, then one side should be mapped as one - it will be responsible for storing the foreign key. Since you have a kind of relationship here, you should map it as one-by-one and use the unique obstacle to treat the relationship from one to the other.


Comments

Popular posts from this blog

c# - ListView onScroll event -

PHP - get image from byte array -

Linux Terminal Problem with Non-Canonical Terminal I/O app -