jpa-streamer icon indicating copy to clipboard operation
jpa-streamer copied to clipboard

Bug in query results

Open doardin opened this issue 4 years ago • 2 comments

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.

doardin avatar Aug 01 '21 22:08 doardin

Can you provide a code snippet showing the problem please?

minborg avatar Aug 04 '21 07:08 minborg

I noticed that bug it happens if you update values directly by database.

INITIAL VALUES

Captura de Tela 2022-03-10 às 11 25 12

Database Captura de Tela 2022-03-10 às 11 08 43

I updated directly by database, the new values is Captura de Tela 2022-03-10 às 11 26 30

but the response of application is the old values of object Captura de Tela 2022-03-10 às 11 27 19

if i restart application the updated values are show Captura de Tela 2022-03-10 às 11 38 59

source code i used to replicate this bug

doardin avatar Mar 10 '22 14:03 doardin

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.

julgus avatar Sep 29 '22 10:09 julgus