Note that there are some explanatory texts on larger screens.

plurals
  1. PONHibernate one-to-many mapping
    primarykey
    data
    text
    <p>I want to map one to many objects Person and PersonAddress</p> <pre><code>public class Person{ public virtual int Id {get; set;} public virtual string FirstName {get; set;} public virtual ICollection&lt;PersonAddress&gt; PersonAddress { get; set; }} public class PersonAddress{ public virtual int Id {get; set;} public virtual int PersonId {get; set;} ... } </code></pre> <p>I don't want to have person object property in address. It creates cyclic references and don't necessary for my application.</p> <p>mapping file is like following:</p> <pre><code>&lt;class name="Person" table="Persons" &gt; &lt;id name="Id" type="Int32" column="PersonId"&gt; &lt;generator class="identity"/&gt; &lt;/id&gt; &lt;set name="PersonAddress" table="PersonAddress" lazy="true" fetch="join" outer-join="true" cascade="all-delete-orphan"&gt; &lt;key column="PersonId"&gt;&lt;/key&gt; &lt;one-to-many class="PersonAddress"/&gt; &lt;/set&gt; &lt;/class&gt; &lt;class name="PersonAddress" table="PersonAddress" &gt; &lt;id name="Id" type="Int32" column="Id"&gt; &lt;generator class="identity"/&gt; &lt;/id&gt; &lt;property name="PersonId" column="PersonId" type="Int32"/&gt; &lt;property name="PhoneWork" column="PhoneWork" type="String"/&gt; &lt;/class&gt; </code></pre> <p>when trying to insert Person with person address I am receiving exception. Because it tries to insert PersonAddress with invalid id (default -1, 0, etc).</p> <p>in samples that I have found it is specified back reference from child to parent
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload