[jboss-user] [Persistence, JBoss/CMP, Hibernate, Database] - Trying to set connection.setReadOnly(true) using Hibernate E

himyouten do-not-reply at jboss.com
Wed Dec 19 05:41:51 EST 2007


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();
			session.connection().setReadOnly(true);
			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?

Cheers,
Himmy

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4114148#4114148

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4114148



More information about the jboss-user mailing list