Hibernate Criteria list doesn't return new records immediate

765 Views Asked by At

I'm using Spring MVC with Hibernate 4.
My problem is when I use Criteria with list() method to fetch all records from the table.

There is a 3rd party process which inserts records to the table every 1 second, and a screen which represent this table as is each time the user press "Refresh" button.
When I use the Criteria.list() on the same session I got records with delay of 45 secs. minimum. Which means the user see records which inserted only before 45 secs.

This is criteria use:

Criteria crit = getCurrentSession().createCriteria(Audit.class);
return ((List<Audit>) crit.list());

This is hibernate + transaction settings:

Session Factory:
<bean id="auditsSessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
        <property name="dataSource" ref="abstractDataSource"/>
        <property name="packagesToScan" value="com.java.model" />
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</prop>
                <!-- Only for debug -->
                <prop key="hibernate.show_sql">true</prop>
                <prop key="hibernate.connection.charSet">UTF-8</prop>
            </props>
        </property>
    </bean>

Transcation Manager:
<bean id="auditsTxManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
        <property name="sessionFactory" ref="auditsSessionFactory"/>
    </bean>

@Transactional setting:

@Transactional(isolation = Isolation.READ_COMMITTED, value = "auditsTxManager")

Also, I'm using: OpenSessionInViewFilter

I've already tried to:

  • Disable query cache
  • Change Isolation level to higher one
  • clear() session

Any suggestions?

Thanks, Tal.

1

There are 1 best solutions below

1
NimChimpsky On

Query cache is not relevant as this uses criteria.

There is a session cache, do you create a new session with each request ?

Are you sure the inserts are inserting new data correctly/and not a problem with the web page displaying correctly. And there is no 2nd level cache ?