2

Has anyone got an idea why JPA Provider - Eclipselink (using version 2.6.0) generates query like:

SELECT ID FROM OPERATION WHERE (ID = ?);

or

SELECT ID FROM SUBSCRIPTION WHERE (ID = ?);

Why it needs to get ID providing an ID...

Maybe 1st or 2nd level Cache synchronization? Maybe my queries are inaccurate... In my queries I never ask directly this to execute - I use JPQL and never ask for ID giving some ID.

I have quite complex model and queries so I see no point in providing full code (or only if U really insist but I dont think it will help a lot). Using Oracle 12c DB.

maciek
  • 83
  • 7
  • 2
    Probably these queries are just checking if the given row exists – antlersoft Jun 21 '16 at 14:19
  • you would have to look at what you have mapped to those tables and what you are executing at the time of the query. Quickest way to find out would be to remove the table and see the stack trace. But they have nothing to do with cache synchronization, as the database is not involved in that unless it needs to read the entire entity in. – Chris Jun 21 '16 at 15:06

1 Answers1

2

We have encountered the same issue with our Java application using EclipseLink 2.5.2. Specifically, we saw it whenever we inserted a new entity that had a M:1 relationship with another entity. A simplified use case would be:

A a = new A(); // the new entity
B b = lookupB(); // get existing entity from database
a.setB(b); // set M:1 relationship
em.persist(a); // save 

In this case, we would always see a query for B (i.e., SELECT ID FROM B WHERE ID = @). After some research, we traced it down to the existence checking that EclipseLink performs before merging records.

We found that annotating the entity class for B with @ExistenceChecking(ExistenceType.ASSUME_EXISTENCE) prevented EclipseLink from running the query.

For a further discussion of this, see this related post.

Community
  • 1
  • 1
Ben Damer
  • 996
  • 7
  • 14