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

  • SEARCH
  • Home
  • 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 6235599
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T10:41:52+00:00 2026-05-24T10:41:52+00:00

I’m just starting out a new project, and am trying to impliment a ISaveOrUpdateEventListener

  • 0

I’m just starting out a new project, and am trying to impliment a ISaveOrUpdateEventListener to set the datecreated and dateupdated fields on my entities.

I’ve been trying to follow a simplified version of the solution found here:
http://fabiomaulo.blogspot.com/2011/05/nhibernate-bizarre-audit.html

Here’s my listener:

Namespace Repositories


    Public Class UpdateAndInsertEventListener
        Implements ISaveOrUpdateEventListener

        Public Sub OnSaveOrUpdate([event] As NHibernate.Event.SaveOrUpdateEvent) Implements NHibernate.Event.ISaveOrUpdateEventListener.OnSaveOrUpdate
            Dim entity = TryCast([event].Entity, IDateCreatedAndUpdated)
            If entity IsNot Nothing Then
                Dim dateUpdated = DateTime.Now

                If entity.DateCreated Is Nothing Then
                    entity.DateCreated = dateUpdated
                End If

                entity.DateUpdated = dateUpdated
            End If
        End Sub


    End Class

End Namespace

and here’s my hibernate.cfg.xml

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
    <session-factory>
        <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
        <property name="dialect">NHibernate.Dialect.MsSql2008Dialect</property>
        <property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
        <property name="connection.connection_string"></property>

        <property name="show_sql">true</property>
        <event type="save-update">
            <listener class="Project.Repositories.UpdateAndInsertEventListener, Project"/>
        </event>

    </session-factory>


</hibernate-configuration>

my problem is, it’s never running the code in my listener, so it’s trying to insert null into my db 🙁 I tried putting break points in, but they are never hit.

I think i’m missing a step somewhere but i’m not sure where.

here’s the stack trace from the failing test:

System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning()
System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
System.Data.SqlClient.SqlDataReader.ConsumeMetaData()
System.Data.SqlClient.SqlDataReader.get_MetaData()
System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async)
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result)
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader()
NHibernate.AdoNet.AbstractBatcher.ExecuteReader(IDbCommand cmd)
NHibernate.Id.IdentityGenerator.InsertSelectDelegate.ExecuteAndExtract(IDbCommand insert, ISessionImplementor session)
NHibernate.Id.Insert.AbstractReturningDelegate.PerformInsert(SqlCommandInfo insertSQL, ISessionImplementor session, IBinder binder)
NHibernate.Id.Insert.AbstractReturningDelegate.PerformInsert(SqlCommandInfo insertSQL, ISessionImplementor session, IBinder binder)
NHibernate.Persister.Entity.AbstractEntityPersister.Insert(Object[] fields, Boolean[] notNull, SqlCommandInfo sql, Object obj, ISessionImplementor session)
NHibernate.Persister.Entity.AbstractEntityPersister.Insert(Object[] fields, Object obj, ISessionImplementor session)
NHibernate.Action.EntityIdentityInsertAction.Execute()
NHibernate.Engine.ActionQueue.Execute(IExecutable executable)
NHibernate.Event.Default.AbstractSaveEventListener.PerformSaveOrReplicate(Object entity, EntityKey key, IEntityPersister persister, Boolean useIdentityColumn, Object anything, IEventSource source, Boolean requiresImmediateIdAccess)
NHibernate.Event.Default.AbstractSaveEventListener.PerformSave(Object entity, Object id, IEntityPersister persister, Boolean useIdentityColumn, Object anything, IEventSource source, Boolean requiresImmediateIdAccess)
NHibernate.Event.Default.AbstractSaveEventListener.SaveWithGeneratedId(Object entity, String entityName, Object anything, IEventSource source, Boolean requiresImmediateIdAccess)
NHibernate.Event.Default.DefaultSaveOrUpdateEventListener.SaveWithGeneratedOrRequestedId(SaveOrUpdateEvent event)
NHibernate.Event.Default.DefaultSaveEventListener.SaveWithGeneratedOrRequestedId(SaveOrUpdateEvent event)
NHibernate.Event.Default.DefaultSaveOrUpdateEventListener.EntityIsTransient(SaveOrUpdateEvent event)
NHibernate.Event.Default.DefaultSaveEventListener.PerformSaveOrUpdate(SaveOrUpdateEvent event)
NHibernate.Event.Default.DefaultSaveOrUpdateEventListener.OnSaveOrUpdate(SaveOrUpdateEvent event)
NHibernate.Impl.SessionImpl.FireSave(SaveOrUpdateEvent event)
NHibernate.Impl.SessionImpl.Save(Object obj)
Project.Repositories.UserRepository.Add(User user) in C:\Projects\Project\Project\Repositories\UserRepository.vb: line 10
Project.Tests.CRUDTest.CRUDTest() in C:\Projects\Project\Project.Tests\Repositories\UserRepository\CRUDTest.vb: line 50

Thanks for the help!

Edit: I’ve changed my helper to add the listener there. it seems to be working for the updates, but when i am creating new entities, it does’t seem to be getting to the listener still. I’ve also removed the “register” sub from my

Imports NHibernate

Namespace Repositories


    Public Class NhibernateHelper

        Private Shared m_sessionFactory As ISessionFactory
        Private Shared ReadOnly Property SessionFactory As ISessionFactory
            Get
                If m_sessionFactory Is Nothing Then
                    Dim config As New NHibernate.Cfg.Configuration
                    config.Configure("C:/Projects/Project/Project.Tests/hibernate.cfg.xml")
                    config.AddAssembly(GetType(Entities.User).Assembly)

                    config.EventListeners.SaveEventListeners =    config.EventListeners.SaveEventListeners.Concat({New UpdateAndInsertEventListener}).ToArray
                    config.EventListeners.SaveOrUpdateEventListeners = config.EventListeners.SaveOrUpdateEventListeners.Concat({New UpdateAndInsertEventListener}).ToArray
                    config.EventListeners.UpdateEventListeners = config.EventListeners.UpdateEventListeners.Concat({New UpdateAndInsertEventListener}).ToArray

                    m_sessionFactory = config.BuildSessionFactory

                End If

                Return m_sessionFactory

            End Get
        End Property

        Public Shared Function OpenSession() As ISession
            Return SessionFactory.OpenSession()
        End Function

    End Class

End Namespace
  • 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-24T10:41:53+00:00Added an answer on May 24, 2026 at 10:41 am

    There is an issue with your registration code:

    listeners.SaveEventListeners.Concat
    

    This does not modify the SaveEventListeners collection, but instead returns a new collection. You need to set the collection.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have just tried to save a simple *.rtf file with some websites and
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I have a jquery bug and I've been looking for hours now, I can't
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I want use html5's new tag to play a wav file (currently only supported
I am trying to render a haml file in a javascript response like so:

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.