2

We have a jsp page on a spring mvc 3 project with hibernate that has two datatables displaying two groups of users. Clicking on a user's name in one table sends a POST transferring the user to the other group, and then the page is reloaded. When the page is initially loaded, the data is shown correctly in both tables. However, after clicking a user to transfer them between groups, the page starts to have issues. Even though the DB is correctly updated, the following method used to pull users out of the DB for the tables starts oscillating between two sets of values on refreshes of the page. One set of values returned is correct, while the other is the data before the DB update. Refreshing this page as many times as wanted will just jump back and forth between the two sets of values ad infinitum.

We are wondering what could cause a hibernate query to oscillate between returning two sets of values, even though the db is not changed in any way between these hibernate queries.

    Session hibernateSession = Utility.getSession();
    try {
        Query notIn = hibernateSession.createQuery("select endUserGroupEndUsers.endUserEndUserId from Endusergroupendusers endUserGroupEndUsers");
        List<Endusers> notinlist = notIn.list();
    } finally {
        hibernateSession.close();
    }
    return notinlist;

Here is our Utility class for hibernate containing the getSession call:

public class Utility {
    private static final SessionFactory ourSessionFactory;
    private static final ServiceRegistry serviceRegistry;

    static {
        try {
            Configuration configuration = new Configuration();
            configuration.configure();

            serviceRegistry = new ServiceRegistryBuilder().applySettings(configuration.getProperties()).buildServiceRegistry();
            ourSessionFactory = configuration.buildSessionFactory(serviceRegistry);
        } catch (Throwable ex) {
            throw new ExceptionInInitializerError(ex);
        }
    }

    public static Session getSession() throws HibernateException {
        return ourSessionFactory.openSession();
    }
}
dima
  • 31
  • 3
  • We stumbled upon the solution, this required setting the isolation level specifically to read-committed, other isolation levels did not work. The solution was found in a comment on http://stackoverflow.com/questions/12035517/hibernate-reading-function-shows-old-data – dima Dec 03 '13 at 16:54

0 Answers0