0 Replies Latest reply on Dec 19, 2007 5:41 AM by Him You Ten

    Trying to set connection.setReadOnly(true) using Hibernate E

    Him You Ten Newbie

      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