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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T23:35:36+00:00 2026-05-20T23:35:36+00:00

NHibernateSessionManager.Instance.GetSessionFrom(SessionFactoryConfigPath).Flush(); i get null id in FoodOrder.Core.Entities.Articles entry (don’t flush the Session after an

  • 0
NHibernateSessionManager.Instance.GetSessionFrom(SessionFactoryConfigPath).Flush();

i get

null id in FoodOrder.Core.Entities.Articles entry (don't flush the Session after an exception occurs)

can i just use try catch and session.Close or what is better to do in this example?

example

public void CommitChanges()
        {
            if (NHibernateSessionManager.Instance.HasOpenTransactionOn(SessionFactoryConfigPath))
            {
                NHibernateSessionManager.Instance.CommitTransactionOn(SessionFactoryConfigPath);
            }
            else
            {
                try
                {
                    // If there's no transaction, just flush the changes
                    NHibernateSessionManager.Instance.GetSessionFrom(SessionFactoryConfigPath).Flush();
                }
                finally
                {
                    NHibernateSessionManager.Instance.GetSessionFrom(SessionFactoryConfigPath).Close();
                }
            }
        }
  • 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-20T23:35:37+00:00Added an answer on May 20, 2026 at 11:35 pm

    After an exception, your session is in an invalid state and should just be disposed. This is one reason why you should always perform writes in a transaction. If not, you have no idea as to the state of your database. So I would recommend that:

    1. You don’t explicitly flush and always insist that data access (reads and writes) are done inside a transaction.
    2. If that’s not an option, I would encourage you to find the root cause of the exception – sounds like you have an entity mapped with an assigned id that was never set – and fix that.
    3. If that’s not an option, then dispose of the session when an exception occurs.

    Hope that helps.

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

Sidebar

Related Questions

I am wondering under what circumstances the following NHibernate code could fail: var session
I'm currently using an Open Session in View pattern in an ASP.NET WebForms application
This is my StructureMap bootstrapping: ObjectFactory.Initialize(factory => { //Business Conversation is per session factory.ForRequestedType<IConversation>().
I had my NHibernate session management setup like follows: protected MvcApplication() { BeginRequest +=
I want to write a nhibernate query to get all employees who are in
i use C# threading and parsing some data and when i try to save
I've got a Criteria Query for a social networking site. A Person object has
I am trying to implement a if exists, update, otherwise, insert data access method
Anyone that can helt me with FluentNhibernate and automapping? Check PotentialReasons collection, and InnerException
I have a criteria query that I am using to show pages of results.

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.