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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T22:01:17+00:00 2026-05-17T22:01:17+00:00

Normally, when you define a mapping for a certain property of a class, NHibernate

  • 0

Normally, when you define a mapping for a certain property of a class, NHibernate saves the value in the property as soon as it has been fetched. Either it’s fetched immediately when getting the object, or it’s lazily loaded on the first invoke of the getter of the property, but once it has been loaded from the database it’s fetched.

Please correct me if I’m wrong.

Is it possible to configure a mapping such that each single invocation of the same getter causes NHibernate to go to the database and read the value again?

Background: I have a table and a corresponding class ExcelFile that manages the path’s and metadata of some Excel files. Each ExcelFile object represents one file.

ExcelFile contains properties IsLocked, LockedBy and DateLocked, with the purpose to lock the file while someone is working on it. As soon as he closes the file, the lock is released.

Caching these properties can introduce race conditions:

  • Alice loads the DB entry to display it. It also displays IsLocked. It’s false. NHibernate caches the value.
  • Bob does the same, it’s false.
  • 5 Minutes later, Alice opens the file: The application checks IsLocked again and then sets the lock.
  • Bob opens the file: The application checks IsLocked which has been cached and is still false. So he sets the lock and opens the application.

For setting the lock, I can live with writing methods that go to the database directly using a native SQL query. So far I did the same for reading the properties.

However I need to query entries with IsLocked being set using HQL. Also the own coding of methods that simply read and write a corresponding table field introduces a second place where mapping logic resists, which is not very nice.

  • 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-17T22:01:18+00:00Added an answer on May 17, 2026 at 10:01 pm

    You probably can do it, I have heard that nHibernate now supports lazy loading of properties which is a step in that direction.

    But having said that, you will still have a race condition. One way you can avoid a race condition is the following:

    1. start a transaction
    2. get the entity via get or refresh (use an upgrade lock, this will avoid deadlocks should bob and alice hit the db at the exact same time)
    3. Check if IsLocked is true, if so abort
    4. Set IsLocked=true
    5. Commit the transaction.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Normally when I create a class, I create a header and a source for
Normally, I've seen prototype functions declared outside the class definition, like this: function Container(param)
Here is a code: >>> class A(object): ... value = [] ... def method(self,
If I define an own assignment operator, which has a different signature than the
Possible Duplicate: Objective-C Default Argument Value I couldn't find a way to define a
i wonder if it's possible to define a variable/property of more than one type.
While designing an interface for a class I normally get caught in two minds
In my .xhtml file, I have the following SelectOneMenu component: <ui:define name=formContent> <h:selectOneMenu value=#{mrBean.itemCategoryID}>
Normally when using a switch statement, you cannot define and initialize variables local to
I know that #define s, etc. are normally never indented. Why? I'm working in

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.