[英]TransactionManager read-only=true does not work with mysql ReplicationDriver
We are using com.mysql.jdbc.ReplicationDriver to connect Master/Slave. 我们正在使用com.mysql.jdbc.ReplicationDriver连接Master / Slave。 We configure the transactionManager as follow. 我们如下配置transactionManager。
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<tx:advice id="txHbAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="get*" read-only="true" />
</tx:attributes>
</tx:advice>
I set the read-only parameter to true but it doesn't set java.sql.Connection.setReadonly()
method to true. 我将只读参数设置为true,但没有将java.sql.Connection.setReadonly()
方法设置为true。 All the read queries are still come to master server. 所有读取的查询仍然会到达主服务器。
There is an open issue for similar problem here . 这里是一个开放的问题类似的问题在这里 。 Is there anyone having a solution to this problem? 有没有人可以解决这个问题?
My suggestion is to write aspect around @Transactional
annotation, get current running session and then invoke doWork(Work work)
→ and set connection.setReadOnly
if @transaction
has readonly attribute set. 我的建议是围绕@Transactional
注释编写方面,获取当前运行的会话,然后调用doWork(Work work)
→并设置connection.setReadOnly
如果@transaction
设置了readonly属性)。 I have not tried this solution, but I think it should work. 我没有尝试过这种解决方案,但我认为它应该起作用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.