Note that there are some explanatory texts on larger screens.

plurals
  1. POIncorrect component when querying immediately after insert using NHibernate
    primarykey
    data
    text
    <p>I have the following mapping for my table in MySql: </p> <pre><code>&lt;class name="Tag, namespace" table="tags" &gt; &lt;id name="id" type="Int32" unsaved-value="0"&gt; &lt;generator class="native"&gt;&lt;/generator&gt; &lt;/id&gt; &lt;property name="name" type="String" not-null="true"&gt;&lt;/property&gt; &lt;component name="record_dates" class="DateMetaData, namespace" &gt; &lt;property name="created_at" type="DateTime" not-null="true"&gt;&lt;/property&gt; &lt;property name="updated_at" type="DateTime" not-null="true"&gt;&lt;/property&gt; &lt;/component&gt; &lt;/class&gt; </code></pre> <p>As you see the record_dates property is defined as a component field of type DateMetaDate. Both created_at and updated_at fields in 'tags' table are updated via triggers. Thus I can insert a new record like such:</p> <pre><code>var newTag = new Tag() { name = "some string here" } Int32 id = (Int32)Session.Save(tag); Session.Flush(); ITag t = Session.Get&lt;Tag&gt;(id); ViewData["xxx"] = t.name; // -----&gt; not null ViewData["xxx"] = t.record_dates.created_at; // -----&gt; is null </code></pre> <p>However when querying the same record back immediately after it was inserted the <code>record_dates</code> field ends up null even though in the table those fields have got values.</p> <p>Can any one please point out why the <code>Session.Get</code> ignores getting everything back from the table? is it because it caches the newly created record for which the records_dates is null? If so how can it be told to ignore the cached version?</p>
    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.
    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