Search code examples
jpaeclipselink

eclipselink.read-only and transaction bounderies


I'm using EclipseLink as my JPA provider. When I use the following code on a query object:

myQuery.setHint("eclipselink.read-only", "true");

The query is executed on a different connection than the original EntityManager is using and return wrong results.
Does it make sense that setting the query to read only will cause EclipseLink to run it on a different connection? (I'm using connection pooling).
In additional I've added in the persistence.xml:

<shared-cache-mode>NONE</shared-cache-mode>

to disable cross session cache.


Solution

  • Read-only queries are meant to only show read-committed data. If you want transactional data, you should not use read-only.

    You may be able to use an exclusive connection, (persistence unit, or persistence context property)

    "eclipselink.jdbc.exclusive-connection.mode"="Always"