jpa-streamer
jpa-streamer copied to clipboard
Bug in query results
I noticed a bug regarding the results of some queries, JPA Streamer does not always return what is actually in the database. My test was simple, I did a specific query that was based on the status of a column, which returned only records whose column specified that record was active and I realized that even after modifying the column's value directly in the database, JPA still returned the record which it shouldn't return, after some tests and revisions I noticed this bug in JPA and for it to return the data correctly I needed to restart the application, I looked for some documentation that talked about it but unfortunately I didn't find anything so decide report this error through github.
Can you provide a code snippet showing the problem please?
I noticed that bug it happens if you update values directly by database.
INITIAL VALUES
Database

I updated directly by database, the new values is

but the response of application is the old values of object

if i restart application the updated values are show

source code i used to replicate this bug
This issue arises as the JPAStreamer instance reuses a single JPA EntityManager throughout its lifetime. JPA's first-level cache automatically caches the query results which means repeated queries are not run against the database but the cache - explaining why the change is not reflected in the application until restart. We are working on a solution for the next release.