Re: How to force a query to use default(write) connection pool?
We ended up created two distinct persistence units, one with
"eclipselink.connection-pool.read.url" and another one without it.
On 6/10/16 1:56 PM, Kohei Nozaki wrote:
> I'm looking for a way to force a query to use default(write) connection
> Let's say we have following properties in persistence.xml:
> <property name="javax.persistence.jdbc.driver"
> <property name="javax.persistence.jdbc.url"
> <property name="eclipselink.connection-pool.read.url"
> value="jdbc:derby:memory:slaveDB;create=true" />
> This makes read queries to be executed in "slaveDB" but I need to
> forcibly execute some read queries on "masterDB" to avoid replication
> lag (I use a MySQL cluster for my real usecase).
> What's the best way to achieve this requirement? it would be great if
> there is a query hint to set the destination of a query to "master"
> forcibly, something like this:
> String mycol = em.createQuery("select m from MyTable m", MyTable.class)
> .setHint("eclipselink.forceMaster", true) // this hint does not exist
> (taken from
> https://github.com/lbtc-xxx/eclipselink-force-write/blob/master/src/test/java/main/ConnectionDestinationTest.java#L68-L75 > )
> I have found a solution which is beginning a transaction then issue a
> native query (e.g. SELECT 1 FROM SYSIBM.SYSDUMMY1) finally issue a JPQL
> query, but looks kludgy.
> (complete testcase:
> https://github.com/lbtc-xxx/eclipselink-force-write/blob/master/src/test/java/main/ConnectionDestinationTest.java#L111-L120 > )