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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T02:14:05+00:00 2026-06-16T02:14:05+00:00

Is there a reason not to use dynamic-insert / dynamic-update for NHibernate? The only

  • 0

Is there a reason not to use dynamic-insert/dynamic-update for NHibernate? The only reason I ask is that it seems to be something that I would want enabled as the default, not as something I would have to configure.

Are there any gotchas to be aware of when using these dynamic properties?

  • 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-06-16T02:14:07+00:00Added an answer on June 16, 2026 at 2:14 am

    For some entities, you may create an invalid state though dynamic updates. Let’s say you’ve got a Class with a Boolean Property A and a logically dependent Integer Property B. If Property A is True, then Property B can only be a negative number, while if Property A is False, then Property B can only be a positive number.

    Let’s say that two users both interact with an instance of this class within a given time span. To start off, users Alice and Bob both materialize this class from the database, with the initial values of A = True and B = -50

    Database   Alice       Bob
    A: True    A: True     A: True
    B: -50     B: -50      B: -50
    VALID      VALID       VALID
    

    User Alice changes A to False and B to 125, and commits it to the database. Now we have this situation:

    Database   Alice       Bob
    A: False   A: False    A: True
    B: 125     B: 125      B: -50
    VALID      VALID       VALID
    

    User Bob doesn’t change A, but changes B to -75, then commits it to the database. If Dynamic updates are on, then NHibernate sees that Bob has only changed B to -75, and issues a dynamic update that only edits the value of B. If you had SQL validation on the server to prevent B from being negative unless A was true, you’d get a SQL error here, but let’s say that you haven’t reproduced all your business logic on your SQL tables. Here is the resulting data:

    Database   Alice       Bob
    A: False   A: False    A: True
    B: -75     B: 125      B: -75
    INVALID    VALID       VALID
    

    Both Alice and Bob have valid states, but the Database is now in an invalid state! User Charlie comes along and tries to materialize this record:

    Database   Alice       Bob       Charlie
    A: False   A: False    A: True   A: False
    B: -75     B: 125      B: -75    B: -75 
    INVALID    VALID       VALID     INVALID
    

    Charlie would likely get a validation error from your application when NHibernate tried to set the B property of the new instance of your class.

    So, when you have logically dependent properties, you must have some strategy in place for avoiding this situation. One possibility is to simply enable select-before-update for this entity. This can result in some additional database calls and a little slower performance. Another is to utilize versioning in NHibernate, which would mean that when Bob tries to save his record, NHibernate’s insert query would not trigger any writes and throw a stale data exception (that can be gracefully handled). You also could codify the logical requirements of your class in the database, however you’ll then have to be cautious to make sure the database and the program both have the same codified requirements as time goes on, and you’ll have multiple places to make changes when requirements change, which isn’t always a worthwhile overhead.

    So in short, in many circumstances a developer must handle the details of dynamic-updates carefully, which is why it is not on by default. When you turn it on, consider if partial updates to your entity could cause problems, and if so, use one of the mitigating strategies I’ve recommended to protect against that issue.

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

Sidebar

Related Questions

Other than convention, is there any reason to use or not to use local
Is there a reason you would not set -static-link-runtime-shared-libraries to true when compiling an
If I'm running a suite of tests, is there a reason I would NOT
Is there a reason that the object TreeSet.apply method returns SortedSet and not TreeSet
Is there any reason for automating tests that focus on GUI (and not to
If so, can the image be animated? Is there a good reason not to
Is there any reason why images are not being displayed if I place it
Is there any reason for my jQuery effects not to be taking effect immediately?
Is there a reason why java does not have a class which allows both
HD7970 vs FirePro V8800 Is there any reason why I should not go with

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.