1) eclipselink L1 cache on PersistenceContext is not cleared. The JPA query returning data from the L1 cache (that to stale cache) instead of from database
2) It seems L1 cache is not cleared or entitymanager is not closed after completion of transaction with container managed transaction
3) Expected Behavior: L1 cache shall be cleared on end of request. The JPA query from the subsequent requests shall return data from database instead of from L1 cache
4) Console Output, for reference. The initial data in the database is description1122335 and later changed to description1122335566. But in some subsequent requests, old data from cache is returned which is description1122335. We can see this from below log.
[EL Config]: 2019-11-27 23:38:28.892--ServerSession(800374351)--Connection(1443737297)--Thread(Thread[helidon-2,5,server])--Connected: jdbc:postgresql://localhost:5432/test?prepareThreshold=5&preparedStatementCacheQueries=256&preparedStatementCacheSizeMiB=5&databaseMetadataCacheFields=65536&databaseMetadataCacheFieldsMiB=5&defaultRowFetchSize=0&binaryTransfer=true&readOnly=false&binaryTransferEnable=&binaryTransferDisable=&unknownLength=2147483647&logUnclosedConnections=false&disableColumnSanitiser=false&tcpKeepAlive=false&loginTimeout=30&connectTimeout=10&socketTimeout=0&cancelSignalTimeout=10&receiveBufferSize=-1&sendBufferSize=-1&ApplicationName=PostgreSQL+JDBC+Driver&jaasLogin=true&useSpnego=false&gsslib=auto&sspiServiceClass=POSTGRES&allowEncodingChanges=false&targetServerType=any&loadBalanceHosts=false&hostRecheckSeconds=10&preferQueryMode=extended&autosave=never&cleanupSavepoints=false&reWriteBatchedInserts=false
User: postgres
Database: PostgreSQL Version: 9.3.25
Driver: PostgreSQL JDBC Driver Version: 42.2.8
[EL Finest]: 2019-11-27 23:38:28.918--ServerSession(800374351)--Thread(Thread[helidon-2,5,server])--sequencing connected, state is NoPreallocation_State
[EL Finest]: 2019-11-27 23:38:28.918--ServerSession(800374351)--Thread(Thread[helidon-2,5,server])--sequence SEQ_GEN_IDENTITY: preallocation size 1
[EL Info]: 2019-11-27 23:38:29.033--ServerSession(800374351)--Thread(Thread[helidon-2,5,server])--/jar:file:/D:/Innorium/iWater-2.0/trunk/app-server-helidon1/target/iWater.jar!/_greeting login successful
[EL Finer]: 2019-11-27 23:38:29.106--ServerSession(800374351)--Thread(Thread[helidon-2,5,server])--Canonical Metamodel class [com.innorium.SampleData_] found and instantiated during initialization.
[EL Finest]: 2019-11-27 23:38:29.11--ServerSession(800374351)--Thread(Thread[helidon-2,5,server])--End deploying Persistence Unit greeting; session /jar:file:/D:/Innorium/iWater-2.0/trunk/app-server-helidon1/target/iWater.jar!/_greeting; state Deployed; factoryCount 1
[EL Finer]: 2019-11-27 23:38:29.164--ServerSession(800374351)--Thread(Thread[helidon-2,5,server])--client acquired: 1384620218
[EL Finer]: 2019-11-27 23:38:29.191--ClientSession(1384620218)--Thread(Thread[helidon-2,5,server])--acquire unit of work: 1729046662
[EL Finest]: 2019-11-27 23:38:29.212--UnitOfWork(1729046662)--Thread(Thread[helidon-2,5,server])--Execute query ReadObjectQuery(name="readSampleData" referenceClass=SampleData sql="SELECT ID, DESCRIPTION, NAME FROM SAMPLEDATA WHERE (ID = ?)")
[EL Finest]: 2019-11-27 23:38:29.22--ServerSession(800374351)--Connection(1339695066)--Thread(Thread[helidon-2,5,server])--Connection acquired from connection pool [read].
[EL Finest]: 2019-11-27 23:38:29.221--ServerSession(800374351)--Thread(Thread[helidon-2,5,server])--reconnecting to external connection pool
[EL Fine]: 2019-11-27 23:38:29.223--ServerSession(800374351)--Connection(158558425)--Thread(Thread[helidon-2,5,server])--SELECT ID, DESCRIPTION, NAME FROM SAMPLEDATA WHERE (ID = ?)
bind => [1]
[EL Finest]: 2019-11-27 23:38:29.23--ServerSession(800374351)--Connection(1339695066)--Thread(Thread[helidon-2,5,server])--Connection released to connection pool [read].
==>getDefaultMessage**description1122335**
[EL Finer]: 2019-11-27 23:38:47.156--UnitOfWork(1941623526)--Thread(Thread[helidon-1,5,server])--TX beforeCompletion callback, status=STATUS_ACTIVE
[EL Finer]: 2019-11-27 23:38:47.158--UnitOfWork(1941623526)--Thread(Thread[helidon-1,5,server])--begin unit of work commit
[EL Finer]: 2019-11-27 23:38:47.185--ClientSession(848484835)--Thread(Thread[helidon-1,5,server])--TX beginTransaction, status=STATUS_ACTIVE
[EL Finest]: 2019-11-27 23:38:47.19--UnitOfWork(1941623526)--Thread(Thread[helidon-1,5,server])--Execute query UpdateObjectQuery(com.innorium.SampleData@61466018)
[EL Finest]: 2019-11-27 23:38:47.215--ServerSession(800374351)--Connection(2075904664)--Thread(Thread[helidon-1,5,server])--Connection acquired from connection pool [default].
[EL Finest]: 2019-11-27 23:38:47.229--ClientSession(848484835)--Thread(Thread[helidon-1,5,server])--reconnecting to external connection pool
[EL Fine]: 2019-11-27 23:38:47.262--ClientSession(848484835)--Connection(174439720)--Thread(Thread[helidon-1,5,server])--UPDATE SAMPLEDATA SET DESCRIPTION = ? WHERE (ID = ?)
bind => [**description1122335566**, 1]
[EL Finest]: 2019-11-27 23:38:47.275--ServerSession(800374351)--Connection(2075904664)--Thread(Thread[helidon-1,5,server])--Connection released to connection pool [default].
[EL Finer]: 2019-11-27 23:38:47.282--UnitOfWork(1941623526)--Thread(Thread[helidon-1,5,server])--TX afterCompletion callback, status=COMMITTED
[EL Finer]: 2019-11-27 23:38:47.297--UnitOfWork(1941623526)--Thread(Thread[helidon-1,5,server])--end unit of work commit
[EL Finer]: 2019-11-27 23:38:47.301--UnitOfWork(1941623526)--Thread(Thread[helidon-1,5,server])--release unit of work
[EL Finer]: 2019-11-27 23:38:47.312--ClientSession(848484835)--Thread(Thread[helidon-1,5,server])--client released
[EL Finer]: 2019-11-27 23:38:54.081--ServerSession(800374351)--Thread(Thread[helidon-3,5,server])--client acquired: 1872402127
[EL Finer]: 2019-11-27 23:38:54.084--ClientSession(1872402127)--Thread(Thread[helidon-3,5,server])--acquire unit of work: 1805979620
[EL Finest]: 2019-11-27 23:38:54.086--UnitOfWork(1805979620)--Thread(Thread[helidon-3,5,server])--Execute query ReadObjectQuery(name="readSampleData" referenceClass=SampleData sql="SELECT ID, DESCRIPTION, NAME FROM SAMPLEDATA WHERE (ID = ?)")
[EL Finest]: 2019-11-27 23:38:54.099--ServerSession(800374351)--Connection(782736628)--Thread(Thread[helidon-3,5,server])--Connection acquired from connection pool [read].
[EL Finest]: 2019-11-27 23:38:54.1--ServerSession(800374351)--Thread(Thread[helidon-3,5,server])--reconnecting to external connection pool
[EL Fine]: 2019-11-27 23:38:54.112--ServerSession(800374351)--Connection(609498224)--Thread(Thread[helidon-3,5,server])--SELECT ID, DESCRIPTION, NAME FROM SAMPLEDATA WHERE (ID = ?)
bind => [1]
[EL Finest]: 2019-11-27 23:38:54.116--ServerSession(800374351)--Connection(782736628)--Thread(Thread[helidon-3,5,server])--Connection released to connection pool [read].
==>getDefaultMessage**description1122335566**
[EL Finest]: 2019-11-27 23:38:54.099--ServerSession(800374351)--Connection(782736628)--Thread(Thread[helidon-3,5,server])--Connection acquired from connection pool [read].
[EL Finest]: 2019-11-27 23:38:54.1--ServerSession(800374351)--Thread(Thread[helidon-3,5,server])--reconnecting to external connection pool
[EL Fine]: 2019-11-27 23:38:54.112--ServerSession(800374351)--Connection(609498224)--Thread(Thread[helidon-3,5,server])--SELECT ID, DESCRIPTION, NAME FROM SAMPLEDATA WHERE (ID = ?)
bind => [1]
[EL Finest]: 2019-11-27 23:38:54.116--ServerSession(800374351)--Connection(782736628)--Thread(Thread[helidon-3,5,server])--Connection released to connection pool [read].
==>getDefaultMessagedescription1122335566
[EL Finer]: 2019-11-27 23:38:55.069--ServerSession(800374351)--Thread(Thread[helidon-4,5,server])--client acquired: 1497165426
[EL Finer]: 2019-11-27 23:38:55.08--ClientSession(1497165426)--Thread(Thread[helidon-4,5,server])--acquire unit of work: 1560506765
[EL Finest]: 2019-11-27 23:38:55.083--UnitOfWork(1560506765)--Thread(Thread[helidon-4,5,server])--Execute query ReadObjectQuery(name="readSampleData" referenceClass=SampleData sql="SELECT ID, DESCRIPTION, NAME FROM SAMPLEDATA WHERE (ID = ?)")
[EL Finest]: 2019-11-27 23:38:55.09--ServerSession(800374351)--Connection(402777161)--Thread(Thread[helidon-4,5,server])--Connection acquired from connection pool [read].
[EL Finest]: 2019-11-27 23:38:55.097--ServerSession(800374351)--Thread(Thread[helidon-4,5,server])--reconnecting to external connection pool
[EL Fine]: 2019-11-27 23:38:55.105--ServerSession(800374351)--Connection(396503366)--Thread(Thread[helidon-4,5,server])--SELECT ID, DESCRIPTION, NAME FROM SAMPLEDATA WHERE (ID = ?)
bind => [1]
[EL Finest]: 2019-11-27 23:38:55.113--ServerSession(800374351)--Connection(402777161)--Thread(Thread[helidon-4,5,server])--Connection released to connection pool [read].
==>getDefaultMessage**description1122335566**
[EL Finest]: 2019-11-27 23:38:55.309--UnitOfWork(**1729046662**)--Thread(Thread[helidon-2,5,server])--Execute query ReadObjectQuery(name="readSampleData" referenceClass=SampleData sql="SELECT ID, DESCRIPTION, NAME FROM SAMPLEDATA WHERE (ID = ?)")
==>getDefaultMessage**description1122335**
[EL Finer]: 2019-11-27 23:38:55.517--ServerSession(800374351)--Thread(Thread[helidon-1,5,server])--client acquired: 490870928
[EL Finer]: 2019-11-27 23:38:55.523--ClientSession(490870928)--Thread(Thread[helidon-1,5,server])--acquire unit of work: 826383480
[EL Finest]: 2019-11-27 23:38:55.536--UnitOfWork(826383480)--Thread(Thread[helidon-1,5,server])--Execute query ReadObjectQuery(name="readSampleData" referenceClass=SampleData sql="SELECT ID, DESCRIPTION, NAME FROM SAMPLEDATA WHERE (ID = ?)")
[EL Finest]: 2019-11-27 23:38:55.538--ServerSession(800374351)--Connection(1635019524)--Thread(Thread[helidon-1,5,server])--Connection acquired from connection pool [read].
[EL Finest]: 2019-11-27 23:38:55.539--ServerSession(800374351)--Thread(Thread[helidon-1,5,server])--reconnecting to external connection pool
[EL Fine]: 2019-11-27 23:38:55.543--ServerSession(800374351)--Connection(1508572716)--Thread(Thread[helidon-1,5,server])--SELECT ID, DESCRIPTION, NAME FROM SAMPLEDATA WHERE (ID = ?)
bind => [1]
[EL Finest]: 2019-11-27 23:38:55.546--ServerSession(800374351)--Connection(1635019524)--Thread(Thread[helidon-1,5,server])--Connection released to connection pool [read].
==>getDefaultMessage**description1122335566**
[EL Finest]: 2019-11-27 23:39:01.374--UnitOfWork(**1729046662**)--Thread(Thread[helidon-2,5,server])--Execute query ReadObjectQuery(name="readSampleData" referenceClass=SampleData sql="SELECT ID, DESCRIPTION, NAME FROM SAMPLEDATA WHERE (ID = ?)")
==>getDefaultMessage**description1122335**
Steps to reproduce
persistence.xml : disabled L2 cache (even tried by enabling L2 cache and still same issue)
Environment Details
1) eclipselink L1 cache on PersistenceContext is not cleared. The JPA query returning data from the L1 cache (that to stale cache) instead of from database 2) It seems L1 cache is not cleared or entitymanager is not closed after completion of transaction with container managed transaction 3) Expected Behavior: L1 cache shall be cleared on end of request. The JPA query from the subsequent requests shall return data from database instead of from L1 cache 4) Console Output, for reference. The initial data in the database is description1122335 and later changed to description1122335566. But in some subsequent requests, old data from cache is returned which is description1122335. We can see this from below log.
Steps to reproduce
persistence.xml : disabled L2 cache (even tried by enabling L2 cache and still same issue)
resource
SampleData entity class
DataSource configuration