JPA and readonly transactions when using mysql replication driver
I'm using Spring 2.5.2/HibernateJpaVendorAdapter/JpaTransactionManager/MySQLReplicationDriver.
If connection.isReadOnly() is true then MySQL's ReplicationDriver uses one of the slave databases, otherwise it uses the master database. To this end, I have set the @Transactional(readOnly=true) annotation whenever I'm doing queries.
Unfortunately, the underlying JpaTransactionManager or HibernateJpaDialect classes never set con.setReadOnly(true) when the readOnly setting is set to true. Here's the code:
@Override
public ConnectionHandle getJdbcConnection(EntityManager entityManager, boolean readOnly)
throws PersistenceException, SQLException {
Session session = getSession(entityManager);
Connection con = session.connection();
return (con != null ? new SimpleConnectionHandle(con) : null);
}
As you can see, the readOnly boolean input never gets used. This differs to say the HibernateTransactionManager that calls DataSourceUtils.prepareConnectionForTransaction() which in turn calls con.setReadOnly(true).
My question is why is it that when using Jpa the con.setReadOnly(true) isn't being set if readOnly has been set to true in the @Transactional annotation?
Cheers
Chico