JPA does not reflect the changed data in the DB manually

4

I have a JavaFX application with Hibernate (JPA).

In this application I update a TableView with the data I search from BD (MySql).

Whenever I click on the system to fetch some data in the DB, it executes the following code:

public Task<List<Pedido>> getPedido(EntityManager em, String numeroPedido){
        return new Task<List<Pedido>>(){
            @Override
            protected List<Pedido> call() throws Exception {                
                TypedQuery<Pedido> query;
                query = em.createQuery("SELECT p FROM Pedido p WHERE p.numPedido = :arg1", Pedido.class);
                query.setParameter("arg1", numeroPedido);
                List<Pedido> lst = query.getResultList();

                return lst;
            }
        };
    }

This execution brings up a list of requests whose order number goes in the WHERE clause. Until then, fine.

Keeping the application open, I go to the DB and manually change the data.

asked by anonymous 27.01.2016 / 16:55

1 answer

2

There is the native implementation of First Level Cache, see here , one solution is do you use .clear() before queries, in your case do you really need these changes directly in the database? Try to avoid this kind of approach.

entityManager.clear();
    
28.01.2016 / 17:08