[hibernate-dev] Mysql master/slave setup with hibernate
Parvin Gasimzade
parvin.gasimzade at gmail.com
Mon Jun 4 11:45:25 EDT 2012
Hi,
I have a mysql master/slave setup which works fine with jdbc datasource.
All inserts goes to the master and all queries goes to the slaves.
I try to access mysql master/slaves using hibernate/spring configuration.
I use org.springframework.orm.hibernate3.HibernateTransactionManager
transaction manager and configure it as follows.
<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="getPopupPage" propagation="REQUIRED" />
<tx:method name="get*" propagation="SUPPORTS" read-only="true" />
<tx:method name="find*" propagation="SUPPORTS" read-only="true" />
<tx:method name="search*" propagation="SUPPORTS" read-only="true" />
<tx:method name="*" propagation="REQUIRED" />
</tx:attributes>
</tx:advice>
But when i run application, all the requests goes to the master. Tomcat
context configuration is as follows :
<Resource name="jdbc/database" auth="Container"
type="com.mchange.v2.c3p0.ComboPooledDataSource"
maxPoolSize="256" minPoolSize="30"
initialPoolSize="5" acquireIncrement="10"
driverClass="com.mysql.jdbc.ReplicationDriver"
factory="org.apache.naming.factory.BeanFactory" user="root" password="root"
jdbcUrl="jdbc:mysql:replication://master:3306,slave1:3306,slave2:3306/database?useUnicode=true&characterEncoding=UTF-
8&autoReconnect=true&roundRobinLoadBalance=true" />
I searched the net but could not find any solution. I only found that
setting transaction manager to read-only could not set
connection.setReadonly(true).
Any help would be appreciated.
Regards,
Parvin
More information about the hibernate-dev
mailing list