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 7488061
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T14:43:35+00:00 2026-05-29T14:43:35+00:00

I would like to intercept persistence operations over collection properties, decide by myself if

  • 0

I would like to intercept persistence operations over collection properties, decide by myself if it can be synchronized with database, and call a procedure when a persistence is decided to occur over all collection at once and not by each element.

How to do that ?

These collection properties are usually mapped with one-to-many or many-to-many associations. So, when we have something like this:

myEntity.List.Add(new Item());
myEntity.List.Add(new Item());
...
session.Save(myEntity);

For a mapping having two classes (entities) and an unidirectional many-to-many association, I would like to have only two sql statements occurring: INSERT INTO, and a PROCEDURE CALL which expects to receive a list of values comma-separated that is the key values from the List collection above. The collection of keys can only be saved on this system calling a procedure with a list of values (csv).

This kind of customizing is possible to be done ?

  • 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-29T14:43:36+00:00Added an answer on May 29, 2026 at 2:43 pm

    Well, I adopted a solution implementing NHibernate Listeners, so I have a listener like that:

    public class CustomSaveUpdateEventListener : IPostInsertEventListener, IPostUpdateEventListener {
    
        private void ScheduleToCommit(AbstractPostDatabaseOperationEvent @event) {
            // Some filter
            if (@event.Entity.GetType().FullName.Equals(MY_ENTITY_TO_INTERCEPTS) {
                object o = @event.Entity;
    
                // Some logic...
                // ...
                // ...
    
                IQuery namedQuery = @event.Session.GetNamedSQLQuery(MY_NAMED_QUERY);
                //namedQuery.SetParameter(...); // <== You can set parameters
                //namedQuery.ExecuteUpdate(); // <== DO NOT EXCEUTE HERE, this launches more events recursively and can generate stackoverflow
    
                @event.Session.ActionQueue.RegisterProcess(new MyActionBeforeCommit(@event, namedQuery).SaveValuesOperation);
                }
            }
        }
    
        public void OnPostInsert(PostInsertEvent @event) {
            ScheduleToCommit(@event);
        }
    
    
        public void OnPostUpdate(PostUpdateEvent @event) {
            ScheduleToCommit(@event);
        }
    }
    

    And my object MyActionBeforeCommit() is scheduled to run only when and if a transaction is commited. So, in my “future action” I have:

    public class MyActionBeforeCommit {
        private AbstractPostDatabaseOperationEvent e;
    
        private IQuery query;
    
        public MyActionBeforeCommit(AbstractPostDatabaseOperationEvent e, IQuery query) {
            this.e = e;
            this.query = query;
        }
    
        public void SaveValuesOperation() {
            // Here your query will be executed only when a transation is commited, if 
            // it's rolledback this won't be executed
            query.ExecuteUpdate(); 
        }
    }
    

    And finally we need to register the new listener on NHibernate configuration, like that:

    Configuration.SetListener(ListenerType.PostInsert, new    CustomSaveUpdateEventListener());
    Configuration.SetListener(ListenerType.PostUpdate, new CustomSaveUpdateEventListener());
    

    And It works very well. This is a very nice NHibernate feature, very powerful.

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

Sidebar

Related Questions

I would like to intercept the Android's OS incoming call screen and replace it
Can I intercept SMS messages on the iPhone? I would like to intercept messages
I would like to intercept the event in a .NET Windows Forms TabControl when
I would like to intercept any URL which the user enters in their browser
I would like to intercept the touch on the camera button to control exactly
I'm packaging a mobile website (over the network) in PhoneGap and would like to
I would like to know how I can access the individual fields contained in
I would like to intercept string starting with \*#\* followed by a number between
I would like to write a google chrome extension to intercept http traffic and
I would like to intercept the < character in the form field by a

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.