-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: MySQL Replication: Reading from slaves - how?
PostPosted: Sat Nov 24, 2007 6:39 am 
Newbie

Joined: Fri May 25, 2007 4:37 am
Posts: 13
Location: Germany
I set up a MySQL Replication Database System with one master and one slave. However, all requests (read/write) go to the master. How must I configure Hibernate to do the reads from the slave?

I heard from a roundRobinLoadBalance property in hibernate.cfg.xml, but this doesnt help.

Do I have to call a special method such as setReadOnly(true); ?

I cannot find any help on the web. No Tutorial, no discussion, no blog that would describe how to set up Hibernate with MySQL Replication.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 26, 2007 4:04 pm 
Regular
Regular

Joined: Wed Aug 15, 2007 7:37 am
Posts: 73
You'll have to set up two session factories, and specify which one to use when loading objects. Writing any changes will be tricky (collections in particular don't like being moved between sessions), but I wouldn't advise writing anything to your master server that you've read from the slave.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 27, 2007 3:49 am 
Newbie

Joined: Fri May 25, 2007 4:37 am
Posts: 13
Location: Germany
SteveMc wrote:
You'll have to set up two session factories, and specify which one to use when loading objects. Writing any changes will be tricky (collections in particular don't like being moved between sessions), but I wouldn't advise writing anything to your master server that you've read from the slave.


Are you sure? Can anybody confirm this?

I mean, why do I configure the MySQL Replication Driver in hibernate.cfg.xml like this, with the master and the slave host?

Code:
<property name="connection.driver_class">com.mysql.jdbc.ReplicationDriver</property>
<property name="connection.url">jdbc:mysql://192.168.178.40:3306,192.168.178.49:3306/mydb?autoReconnect=true</property>


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.