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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T07:46:23+00:00 2026-05-12T07:46:23+00:00

I am working on the project which uses NHibernate. I don’t keep session opened.

  • 0

I am working on the project which uses NHibernate.
I don’t keep session opened. When i need to get or save object, i open the session, do what i need and then close the session. So all the time i’m working with objects detached from session.

For example, when i need to get object from the database, i open the session, then call session.Get() and close the session. Then i update some properties of detached object. When i need to save changes to the database i call method that opens session, calls session.Update(myObject) and closes the session.

But when i do so, NHibernate generates sql that updates all the fields I have mapped, even though they have not changed. My suggestion is when objects is detached from session, NHibernate couldn’t track the changes has been made.
What approach do you use when you want to update only properties that has been changed for object detached from session? How do you track the changes for detached objects?

Thanks

  • 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-12T07:46:23+00:00Added an answer on May 12, 2026 at 7:46 am

    The question is: why do you want to do this? I think it is not much of an optimization if you only update columns that have changed.

    Have you got triggers in the database?

    If so, you can do the following:

    • use select-before-update="true" and dynamic-update="true" in the mapping. This makes NH to perform a query before the update and only updates if it changed, and only the columns that have changed. I’m not sure if it selects for every update, or only if it is not in the session.
    • use Merge instead of update. This does actually the same: it selects the entity from the database, only if it is not already in the session. Also use dynamic-update="true". There is also a trade-off: Merge returns the attached instance if there is already one in the session. So you should always throw away the instance you passed in and work with the instance you go from Merge.

    Actually I wouldn’t care about the updated columns. Its most probably faster to update them blindly instead of performing a preceding query.

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

Sidebar

Ask A Question

Stats

  • Questions 323k
  • Answers 323k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You can set the timeout in your connection string. Edit… May 14, 2026 at 1:00 am
  • Editorial Team
    Editorial Team added an answer Can I set the max size of the ArrayCollection? The… May 14, 2026 at 1:00 am
  • Editorial Team
    Editorial Team added an answer Use fixtures. See the documentation or the (wiki page](https://code.djangoproject.com/wiki/Fixtures) Put… May 14, 2026 at 1:00 am

Related Questions

I am working on the project which uses NHibernate. I don't keep session opened.
I am working on a project which uses Java,MySql,Struts2 MVC and Hibernate. I tried
I am working on a project which was developed in Visual Studio 2005 (.NET
I'm currently the only developer using Eclipse Mylyn integration (I'm the experimental one). I
I am working on a project which uses an import #import progid:Blah.blah.retrieve rename_namespace(Blah) but

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.