Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » JPA READ_ONLY query uses wrong connection
JPA READ_ONLY query uses wrong connection [message #1552900] Thu, 08 January 2015 11:37
Chris Wesdorp is currently offline Chris WesdorpFriend
Messages: 1
Registered: January 2015
Junior Member
Hello,

after an upgrade from EclipseLink 2.3.2 to 2.5.2 we encountered something strange when a READ_ONLY query was executed inside a running transaction.

Attached is a sample app that tries to insert a record and then tries to query this via a READ_ONLY query

            transaction.begin();

            // create a new record and persist it
            SomeEntity se = new SomeEntity();
            se.setSomeValue("This is a new entity");
            em.persist(se);
            em.flush();     // force insert in the database, creates an id

            // try to query this new record
            Query query = em.createQuery("SELECT e FROM SomeValue e WHERE e.id = :id");
            query.setParameter("id", se.getId());
            query.setHint(QueryHints.READ_ONLY, HintValues.TRUE);

			// query
            SomeEntity justPersistedEntity = (SomeEntity) query.getSingleResult();
            System.out.println(justPersistedEntity.getId());

            transaction.commit();


What happens when query.getSingleResult() is executed that inside this (EclipseLink) transaction a new connection to the database is started on which this query is executed. Because 'se' is not yet committed it will not be readable by this new connection. However, I would expect this query would use the same transaction/connection as before.

With MySQL this results in a exception (NoResultException). On MS SQL Server the behaviour is even worse on a database with default settings, (READ_COMMITTED, READ_COMMITTED_SNAPSHOT = Off), it results in a deadlock.

In version 2.3.2 this works fine.
We suspect the cause of this behavior is bug issue number 382410 in version 2.4.1. (Sorry, adding the link here gives a post error)

Even though it might make sense to use a different connection for read_only queries, i would not expect this to happen when data is already modified in the transaction. Eclipselink knows when data has been altered.

Is this a bug or feature?

Chris
Previous Topic:Nondeterministic exception when creating JAXBContext
Next Topic:IN with subquery
Goto Forum:
  


Current Time: Sat Nov 09 02:30:02 GMT 2024

Powered by FUDForum. Page generated in 0.02939 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top