I'm using the MySql Connect/J ReplicationDriver to connect to my MySql master and slave databases.
I modified my -ds.xml file to use the ReplicationDriver and have both the master and slave in the connection-url.
It starts up fine but when I try to make a query go to the slave it throws an error:
You cannot set read only during a managed transaction!
The code snippet is inside a stateless bean:
HibernateSession hs = (HibernateSession) em;
Session session = hs.getHibernateSession();
Query q = em.createQuery(query);
I'm not sure this is the correct way to set the connection to read only when using EntityManager but I can't see any other way via annotations or other settings.
Is there any way to get the query to be sent to the slave? Use two entitymanagers with different ds?