Mismatch hibernation: the session returns the old value

I am using Hibernate for a JSF project.

On the main page, I have a datatable representing a list of objects.

I am successfully doing an update on the property of an object (found in datatable) using Hibernate. After the refresh, the page is refreshed by redirecting using "xxx? Faces-redirect = true". I am redirecting the page to avoid problems with duplicate forms.

Then, if I press F5 several times, the value of the old version of the updated object may return to the page.

As I understand it, this is a Hibernate session problem. Because if I close every session after using them, this problem does not occur. However, due to the lazy retrieval strategy, I cannot close sessions after transactions.

In short, hibernate can fetch the old value of an object, although it has been successfully updated. How can I avoid such a problem?

ps: I suspected Hibernate caching mechanisms, and I disabled the first and second level cache using:

<property name="hibernate.cache.use_query_cache">false</property>
<property name="hibernate.use_second_level_cache">false</property>

but that didn't work either.

Update. Following @Johanna's answer, I controlled the session instance identifiers and noticed that my HibernateUtil class returns most of the time or opens a new session. Here is the getSession () method:

public static Session getSession(){
    Session se = HibernateUtil.session.get();
    if(se == null)
    {
        se = sessionFactory.openSession();
        HibernateUtil.session.set(se);
    }
    return se;
}

I assumed that as soon as I have a session, I do all such enumeration, updating, etc. with this session. Because I'm doing the necessary controls in the getSession () method. Where can I make a mistake?

+3
source share
1 answer

use_query_cache, use_second_level_cache . .

, StatelessSession . StatelessSession , , , .

, Session.evict().

, Hibernate . , ( , , , ). , . Hibernate ( , , ). , , .

: , , .

: JSF, , , -, .

Hibernate , i. . , , , . . , Hibernate Http ( "" ( ) , , ).

2nd EDIT: , , .

, , DAO . , HibernateUtil, , hibernate ThreadLocal, .. . .

-. Hibernate ( ), .. . Http. , http. , Http Hibernate , , Http- Hibernate. Http-.

. Hibernate Http ( ThreadLocal). Http HttpServletRequest.getSession() HttpSession.getAttribute()/HttpSession.setAttribute() Hibernate Http- .

+4

All Articles