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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T13:22:49+00:00 2026-05-13T13:22:49+00:00

I have a repository class that uses an NHibernate session to persist objects to

  • 0

I have a repository class that uses an NHibernate session to persist objects to the database. By default, the repository doesn’t use an explicit transaction – that’s up to the caller to manage. I have the following unit test to test my NHibernate plumbing:

[Test]
public void NHibernate_BaseRepositoryProvidesRequiredMethods()
{            
    using (var unitOfWork = UnitOfWork.Create())
    {
        // test the add method
        TestRepo.Add(new TestObject() { Id = 1, Name = "Testerson" });
        TestRepo.Add(new TestObject() { Id = 2, Name = "Testerson2" });
        TestRepo.Add(new TestObject() { Id = 3, Name = "Testerson3" });

        // test the getall method
        var objects = TestRepo.GetAll();
        Assert.AreEqual(3, objects.Length);

        // test the remove method
        TestRepo.Remove(objects[1]);
        objects = TestRepo.GetAll();
        Assert.AreEqual(2, objects.Length);

        // test the get method
        var obj = TestRepo.Get(objects[1].Id);
        Assert.AreSame(objects[1], obj);
    }
}

The problem is that the line

Assert.AreEqual(3, objects.Length);

fails the test because the object list returned from the GetAll method is empty. If I manually flush the session right after inserting the three objects, that part of the test passes. I’m using the default FlushMode on the session, and according to the documentation, it’s supposed to flush before running the query to retrieve all the objects, but it’s obviously not. What I am missing?

Edit: I’m using Sqlite for the unit test scenario, if that makes any difference.

  • 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-13T13:22:50+00:00Added an answer on May 13, 2026 at 1:22 pm

    You state that

    according to the documentation, it’s supposed to flush before running the query to retrieve all the objects

    But the doc at https://www.hibernate.org/hib_docs/v3/api/org/hibernate/FlushMode.html, the doc states that in AUTO flush mode (emphasis is mine):

    The Session is sometimes flushed
    before query execution in order to
    ensure that queries never return stale
    state. This is the default flush mode.

    So yes, you need to do a flush to save those values before expecting them to show up in your select.

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

Sidebar

Related Questions

I have a repository class that inherits from a generic implementation: public namespace RepositoryImplementation
I'm using Spring 3.0.2 and I have a class called MovieDAO that uses JDBC
I have a repository (warehouse, call it what you wish) that uses templates and
Our architecture uses the Repository pattern extensively. We have an abstract base class for
I have this code that uses NHibernate public bool ValidateUser(string username, string password) {
I have the following Spring MVC controller that uses both a repository and an
I have an MVC app that uses NHibernate for ORM. Each controller takes an
Say I have two separate classes, A and B. I also have Repository class
I have a repository Class which takes in a ObjectContext called TestDB. I when
I have a Repository Class with the following method... public T Single<T>(Predicate<T> expression) {

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.