title: How to split read-only and read-write transactions with JPA and Hibernate
body: <p>I have a quite heavy java webapp that serves thousands of requests/sec and it uses a master Postgresql db which replicates itself to one secondary (read-only) database using streaming (asynchronous) replication.</p>
  
  <p>So, I separate the request from primary to secondary(read-only) using URLs to avoid read-only calls to bug primary database considering replication time is minimal.</p>
  
  <p><strong>NOTE</strong>: <em>I use one sessionFactory with a RoutingDataSource provided by spring that looks up db to use based on a key. I am interested in multitenancy as I am using hibernate 4.3.4 that supports it.</em></p>
  
  <p>I have two questions:
  <br></p>
  
  <ol>
  <li>I dont think splitting on the basis of URLs is efficient as I can
  only move 10% of traffic around means there are not many read-only 
  URLs. What approach should I consider?</li>
  <li>May be,somehow, on the basis of URLs I achieve some level of
  distribution among both nodes but what would I do with my quartz
      jobs(that even have separate JVM)? What pragmatic approach should I 
      take?</li>
  </ol>
  
  <p>I know I might not get a perfect answer here as this really is broad but I just want your opinion for the context.</p>
  
  <p>Dudes I have in my team:</p>
  
  <ul>
  <li>Spring4</li>
  <li>Hibernate4</li>
  <li>Quartz2.2</li>
  <li>Java7 / Tomcat7</li>
  </ul>
  
  <p>Please take interest. Thanks in advance.</p>