Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7057861
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:02:39+00:00 2026-05-28T04:02:39+00:00

I’m attempting to implement an automatic LastUpdate attribute to my NHibernate entities. I thought

  • 0

I’m attempting to implement an automatic LastUpdate attribute to my NHibernate entities. I thought about using database triggers and then thought it better done in NHibernate. I am following this blog post as a guide.

My domain entity is:

public class Instrument : Entity, IAuditableEntity
{
    public virtual string Name { get;  set; }
    public virtual string Symbol {get;  set;}
    public virtual ISet<BrokerInstrument> BrokerInstruments { get; set; }
    public virtual bool IsActive { get; set; }        
}

which inherits from

public abstract class Entity
{
    public virtual int Id { get; set; }
    public virtual int Version {get; private set;}
    public virtual DateTime CreateDate { get; private set; }
    public virtual DateTime UpdateDate { get; set; }
}

and here’s the interface:

public interface IAuditableEntity
{
    DateTime UpdateDate { get; set; }
}

My listener class:

public class CustomUpdateEventListener : DefaultSaveEventListener
{
    protected override object PerformSaveOrUpdate(SaveOrUpdateEvent evt)
    {
        var entity = evt.Entity as IAuditableEntity;
        if (entity != null)
        {
            ProcessEntityBeforeUpdate(entity);
        }
        return base.PerformSaveOrUpdate(evt);
    }

    internal virtual void ProcessEntityBeforeUpdate(IAuditableEntity entity)
    {
        entity.UpdateDate = DateTime.Now;
    }
}

and my domain entity Instrument mapping file:

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="MooDB"  namespace="MooDB" >
  <class name="MooDB.Domain.Instrument,MooDB"  table="instruments">
    <id name="Id" column="instrumentId" unsaved-value="0">
      <generator class="increment"></generator>
    </id>
    <version name="Version" column="version" type="integer" unsaved-value="0"/>
    <property name="Symbol" column="symbol" type="string" length="10" not-null="false"/>
    <property name="Name" column="`name`" type="string" length="30" not-null="false"/>
    <property name="IsActive" column="isActive" type="bool" not-null="true" />
    <set name="BrokerInstruments" table="brokerInstruments" generic="true" inverse="true">
      <key column="instrumentId" />
      <one-to-many class="MooDB.Domain.BrokerInstrument"/>
    </set>
    <property name="CreateDate" column="created" not-null="false" />
    <property name="UpdateDate" column="lastUpdated" />
  </class>
</hibernate-mapping>

My hibernate.cfg.xml:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2" >
  <session-factory>
  ... connection details snipped
    <mapping assembly="MooDB"/>
    <listener class="MooDB.Data.CustomUpdateEventListener, MooDB.Data" type="update" />
  </session-factory>
</hibernate-configuration>

My solution builds fine but I am getting a FileNotFoundException when NHibernate tries to find the listner. My references are set up correctly and I have the right using statements, so I’m not sure why NHibernate can’t find it. Here’s the error from the log:

2012-01-15 15:26:12,911 [TestRunnerThread] ERROR
NHibernate.Util.ReflectHelper [(null)] – Could not load type
MooDB.Data.CustomUpdateEventListener, MooDB.Data.
System.IO.FileNotFoundException: Could not load file or assembly
‘MooDB.Data’ or one of its dependencies. The system cannot find the
file specified. File name: ‘MooDB.Data’

Do you know what could be wrong?

Edit: I’m now getting the following SqlTypeException:

2012-01-15 17:06:37,302 [TestRunnerThread] ERROR NHibernate.AdoNet.AbstractBatcher [(null)] – Could not execute command: UPDATE instruments SET version = @p0, symbol = @p1, [name] = @p2, isActive = @p3, created = @p4, lastUpdated = @p5 WHERE instrumentId = @p6 AND version = @p7 System.Data.SqlTypes.SqlTypeException: SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM.

It seems that the code entity.UpdateDate = DateTime.Now; in ProcessEntityBeforeUpdate is not being run for some reason. Any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T04:02:39+00:00Added an answer on May 28, 2026 at 4:02 am

    It’s looks like your’s assembly name is wrong. try this:

    <listener class="MooDB.Data.CustomUpdateEventListener, MooDB" type="update" />
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am reading a book about Javascript and jQuery and using one of the
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have thousands of HTML files to process using Groovy/Java and I need to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.