Related Documentation Download this Manual Excerpts from this Manual


This page has moved or been replaced. The new page is located here:

Please update any bookmarks that point to the old page.

Download this Manual
User Comments
  Posted by rufus hamade on September 7, 2009
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 form
jdbc: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, though that is fixed in version 5.1.7 it seems.)
Sign Up Login You must be logged in to post a comment.