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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:00:09+00:00 2026-05-23T08:00:09+00:00

Is there Interceptor, EventListener or anything in NHibernate that is executed after retrieving entity

  • 0

Is there Interceptor, EventListener or anything in NHibernate that is executed after retrieving entity from the database and before inserting it to the 2nd level cache?

I have a class with a property which might contain something like

Lorem ipsum <c:link type="tag" id="123" /> dolor sit amet

and I need to run plugins that transform it to

Lorem ipsum <a class="tag-link" href="/tags/tag-name/" title="Description of the tag">Tag name</a> dolor sit amet

And if cache is enabled I want to do that only once: before that entity is inserted to the cache.

  • 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-23T08:00:10+00:00Added an answer on May 23, 2026 at 8:00 am

    I found a possible solution: UserTypes.

    Entity

    public class Post : Page
    {
        [FormattedText]
        public virtual string Text { get; set; }
    }
    

    Mapping

    public class PostMapping : SubclassMap<Post>
    {
        public PostMapping()
        {
            Map(x => x.Text);
        }
    }
    

    UserType (part of it)

    public class FormattedText: IUserType
    {
        public object NullSafeGet(System.Data.IDataReader rs, string[] names, object owner)
        {
            string original = (string)NHibernateUtil.String.NullSafeGet(rs, names[0]);
            // this is where we do the text processing
            // TODO: the real implementation
            return new string(original.Reverse().ToArray());
        }
        // ...
    }
    

    Fluent NHibernate Convention for mapping the custom type

    public class FormattedTextConvention : IPropertyConvention
    {
        public void Apply(IPropertyInstance instance)
        {
            if (instance.Property.PropertyType == typeof(string))
            {
                if (instance.Property.MemberInfo.GetCustomAttributes(typeof(FormattedTextAttribute), true).Any())
                {
                    instance.CustomType<FormattedText>();
                }
            }
        }
    }
    

    Creating SessionFactory

    public class NHibernateThingy
    {
        public static ISessionFactory CreateSessionFactory(bool isAdminMapping)
        {
            var config = Fluently.Configure();
            config.Database(/* ... */);
            if (isAdminMapping)
            {
                // don't format strings when editing entities
                // so no FormatTextConvetion here
                config.Mappings(m => m.FluentMappings.AddFromAssemblyOf<Content>());
            }
            else
            {
                // format string when displaying
                config.Mappings(m => m.FluentMappings.AddFromAssemblyOf<Content>().Conventions.Add(typeof(FormattedTextConvention)));
                // use cache to run that heavy text processing only once
                config.Cache(c => c.ProviderClass<SysCacheProvider>().UseSecondLevelCache());
            }
    
            return config.BuildSessionFactory();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have a project that uses an Interceptor object to tell NHibernate to do
I'm trying to access the database from Hibernate Interceptor (I need to audit only
I'm trying to use NHibernate with an existing database. In the data-model there is
Is it possible to manually change an entity when it's loaded from the database
I am working on struts2. I have an interceptor that executes before my action
Is there a way to intercept window messages from another app other than a
There is a conversion process that is needed when migrating Visual Studio 2005 web
I'm trying to write an interceptor for a web service that will modify the
Is there way to bind a method interceptor to a provider rather than an
We have Interceptor, we have custom interceptor where we can do all that we

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.