Login | Register
Section 8.3, “Master/Slave Replication with ReplicationConnection”
for details on the topic.
Copyright © 1998, 2014, Oracle and/or its affiliates. All
I had a lot of difficulty getting the replication connection working with JPA/Hibernate. The connection associated with the entity manager would always connect to the master, irrespective of whether I set the connection readonly or read/write (via calls to ((Session)em.getDelegate()).connection().setReadOnly(true);)After trawling through the source code for Connector/J, I discovered that the driver understands URLs of the formjdbc:mysql:replication://[server1],[server2],[server2]/[database]. Using such a URL in my persistence.xml makes everything work splendidly. (I am using MySQL 5.0.something, Connector/J version 5.1.6. (Though I got the URL format by looking at the source for version 5.1.8. Thank god for open source.) I specify the last slave server twice to work around bug http://bugs.mysql.com/bug.php?id=39611, though that is fixed in version 5.1.7 it seems.)