I use in the project such a terrible thing as EJB. More to the point, there are functions that add a lot of data to the database at once and they are synchronized immediately with the EJB, and there are methods that add one tuple and there is no synchronization with the EJB. I read in the JEE6 Tutorial that I need to use flush (), I tried it, but it did not help. Maybe someone knows how to force synchronization :-)

I use NetBeans 6.9.1, all classes of Entity, Session generated using it, as AppServer'a GlassFish out of the box with NetBeans.

    2 answers 2

    As I understand it, you use Java Persistence technology to work with the database. In this case, a similar error can occur if you write to the database using the native query. Disable Persistence Cache or use JPQL. Also, pay attention to the fact that you correctly reference the links when using the related entity. Out-of-sync is usually due to the fact that the database has changed data, but the JPA cache is still not there.

      I solved the problem by adding the following 2 operations to the facade methods:

      getEntityManager.flush(); getEntityManager.refresh(entity); 

      thus, the data is immediately added to the db and synchronization with ejb occurs.