| It's not limited to a race condition, but it was caused by a race condition in our case. Below is the query, which uses EM.createNativeQuery (only) and so needs isZeroBasedParametersIndex=false (only). Despite being run 1000s of times in a large cloud application, the error only happened once. Looking at AbstractSharedSessionContract.createNativeQuery(), the race condition could manifest on the 1st and 2nd query (same query run on different threads), or the two queries run after a query plan is evicted from QueryPlanCache.queryPlanCache which is a BoundedConcurrentHashMap.
NativeQueryImplementor query = entityManager.createNativeQuery("select {confpage.*} " +
"from CONFANCESTORS ancestors, CONTENT {confpage} " +
"where {confpage}.CONTENTID = ancestors.DESCENDENTID " +
"and ancestors.ANCESTORID = ? " +
"order by {confpage}.CONTENTID", "confpage", Page.class);
query.setCacheable(true);
query.setLong(1, page.getId());
return query.list();
|