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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T11:08:13+00:00 2026-05-13T11:08:13+00:00

I have written an integrationtest that fails: [Test] public void Find_WorkItemWithMatchingDescriptionExistsInRepository_ReturnsWorkItem() { // arrange

  • 0

I have written an integrationtest that fails:

    [Test]
    public void Find_WorkItemWithMatchingDescriptionExistsInRepository_ReturnsWorkItem()
    {
        // arrange
        WorkItemRepository repository = new WorkItemRepository(IsolatingFactory);

        const string Description = "A";
        WorkItem itemWithMatchingDescription = WorkItem.Create(1, Description);
        repository.Commit(itemWithMatchingDescription);

        // act
        List<WorkItem> searchResult = repository.Find(Description);

        // assert
        CollectionAssert.Contains(searchResult, itemWithMatchingDescription);
    }

When watching the sql output from nhibernate i notice that it creates a select-statement for the repository.Find() operation, but no insert operation before the select. If i put an explicit session.Flush() after the repository.Commit it works as expected, but I find this behaviour odd. Why doesn’t nhibernate flush the session automatically when there are pending insert and a query is performed against the session?

I found this in the documentation:

9.6. Flush

From time to time the ISession will execute the SQL statements needed to synchronize the ADO.NET connection’s state with the state of objects held in memory. This process, flush, occurs by default at the following points

* from some invocations of Find() or Enumerable()
* from NHibernate.ITransaction.Commit()
* from ISession.Flush() 

It looks as the default nhibernate behaviour is to flush before quering by find. My repository uses Ling to nhibernate for the query specification, maybe this is a bug.

Update

If I change my mapping from:

    public WorkItemClassMap()
    {
        Not.LazyLoad();

        Id(wi => wi.Id).GeneratedBy.Assigned();
        Map(wi => wi.Description).Length(500);
        Version(wi => wi.LastChanged).UnsavedValue(new DateTime().ToString());
    }

To:

    public WorkItemClassMap()
    {
        Not.LazyLoad();

        Id(wi => wi.Id).GeneratedBy.Identity();
        Map(wi => wi.Description).Length(500);
    }

It works as expected (nhibernate flushes the insert to the database before performing the query). I can’t see any good reason for this behavior so I’m assuming its a bug. Looks like a need to do manual flush before querying in my repositories, which is not something I really want to do.

  • 1 1 Answer
  • 1 View
  • 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-13T11:08:13+00:00Added an answer on May 13, 2026 at 11:08 am

    Is WorkItem in your example mapped with a composite ID? I just coded a simple test. My dummy class would auto flush when I had a single identity column. I wrote the same test though with a composite ID and I get the behavior you describe above.

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

Sidebar

Related Questions

I have written a function that sorts a big scale of data. To test
I have written this piece of code: namespace { void SkipWhiteSpace(const char *&s) {
I have written a function that extract the domain from hostname. e.g. www.domain.com ->
I have written a very simple CTE expression that retrieves a list of all
Have written the following code: m_selectCategoryTableWidget = new QTableWidget; m_selectCategoryTableWidget->setRowCount(0); m_selectCategoryTableWidget->setColumnCount(2); m_selectCategoryTableWidget->setHorizontalHeaderLabels(QStringList()<<tr(Category)<<tr(Number of items));
I have written a xml/php document that is pulling from a Magento Commerce database,
I have written the following code. I know that a higher order function is
I have written a WCF service with the REST template that has the defaultOutgoingResponseFormat
I have written a recursive DFS algorithm to traverse a graph: void Graph<E, N>::DFS(Node
So say I'm doing TDD and I write a test like this: public void

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.