Description
Eduardo Simioni opened SPR-15759 and commented
Our setup uses
org.springframework.orm.hibernate5.HibernateTransactionManager
and
org.springframework.orm.hibernate5.LocalSessionFactoryBean
Hibernate 5.2.10.Final
We also use compile time aspects for the transactions, although I don't think this would be a determinant factor for this bug.
The problem
I've put the following code inside a @Transactional(readOnly = true)
method (the only transactional method in the chain):
LOG.info("Hibernate flush: " + sessionFactory.getCurrentSession().getHibernateFlushMode());
LOG.info("JPA flush: " + sessionFactory.getCurrentSession().getFlushMode());
This yielded the following result:
Hibernate flush: MANUAL
JPA flush: COMMIT
Plus the following Hibernate log line:
[org.hibernate.jpa.internal.util.FlushModeTypeHelper] Interpreting Hibernate FlushMode#MANUAL to JPA FlushModeType#COMMIT; may cause problems if relying on FlushMode#MANUAL-specific behavior
I've noticed this by chance. After setting one of our main queries (single method request) to FlushMode.MANUAL
, the total request time dropped from 550ms to 110ms on average.
Most of the time was being spent on Hibernate checking dirty entities, which led me to conclude that Spring was not setting the FlushMode
correctly.
I'm not sure if this bug is present on 5.0 branch, but since I didn't find any similar issue, I'd guess it is.
Affects: 4.3.9, 5.0 RC2
Issue Links:
- Propagate read-only status to Hibernate Session through setDefaultReadOnly [SPR-16956] #21494 Propagate read-only status to Hibernate Session through setDefaultReadOnly