Incorrect component when querying immediately after insert using NHibernate

Posted by Am on Stack Overflow See other posts from Stack Overflow or by Am
Published on 2010-04-05T04:39:06Z Indexed on 2010/04/05 4:43 UTC
Read the original article Hit count: 232

Filed under:
|
|

I have the following mapping for my table in MySql:

<class name="Tag, namespace" table="tags" >
 <id name="id" type="Int32" unsaved-value="0">
   <generator class="native"></generator>
 </id>
 <property name="name" type="String" not-null="true"></property>
 <component name="record_dates" class="DateMetaData, namespace" >
   <property name="created_at" type="DateTime" not-null="true"></property>
   <property name="updated_at" type="DateTime" not-null="true"></property>
 </component>
</class>

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:

var newTag = new Tag() 
{ 
 name = "some string here"
}

Int32 id = (Int32)Session.Save(tag);
Session.Flush();

ITag t = Session.Get<Tag>(id);
ViewData["xxx"] = t.name; // -----> not null
ViewData["xxx"] = t.record_dates.created_at; // -----> is null

However when querying the same record back immediately after it was inserted the record_dates field ends up null even though in the table those fields have got values.

Can any one please point out why the Session.Get 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?

© Stack Overflow or respective owner

Related posts about nhibernate

Related posts about ASP.NET