Sometimes, I query data from database using EclipseLink. The query as below:
EntityManager em;I get nothing but when I access to database, some record exists in table Tbexample.
em.createQuery("SELECT o FROM Tbexample as o", Tbexample.class).getResultList();
Cause
By default, EclipseLink enable caching feature. This feature help increase performance but sometimes it make difficult to control real data in database in very small time (nanosecond). So to ensure the query result show real data on table of database, you have to disable caching feature.
Solution
On persistence.xml, add the line:
<shared-cache-mode>NONE</shared-cache-mode>
On query, add the hint
EntityManager em;That's all for disable caching feature on querying.
em.createQuery("SELECT o FROM Tbexample as o", Tbexample.class).setHint("javax.persistence.cache.storeMode", "REFRESH").getResultList();