Hi!
I use the classic HibernateSessionRequestFilter as described in:
http://www.hibernate.org/43.htmlIf I update a table in the database, that update is visible to concurrent requests on a windows server. But not on a Linux server. To fix that on linux I had to make the doFilter-method synchronized
Code:
public synchronized void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) {
...
log.debug("Starting a database transaction");
sf.getCurrentSession().beginTransaction(); // IF 2 requests hit this before commit() is called later on, then they will both see the updated table as it was befor any of the requests started. This is only true on linux. Thus this method is now synchronized to prevent that for happening
chain.doFilter(request, response);
sf.getCurrentSession().getTransaction().commit();
...
Most of the applications operations are read only. So synchronized is perhaps not good for preformance.
What is the correct way to handle this issu?