Changes directly in the database reflect in the managed bean?

1

I'm developing a simple web application, a form. I did the DAO's, Facades and they are working correctly (at least I think they are) but I will also need to edit some values directly in the bank only these changes are not being reflected in the application, for example, the bank contains the " student "with value 20, and this value is normally loaded and displayed in the application, when doing the value editing by the application the value is normally edited, but when performing manual editing (replace 20 by 30 directly in the bank for example) and reload the view, JSF goes through all the necessary methods (an init () method annotated with @PostConstruct) but does not display the changed value but rather the old value.

I have already tried with @RequestScoped and @ViewScoped. Is this normal?

I'm using JSF2.2, EclipseLink, MySQL and JPA.

    
asked by anonymous 06.02.2014 / 20:37

2 answers

2

First, make sure the change is isolated in an unapplied transaction. If it is, make commit so that the values are read correctly by the application.

It may still be occurring that the values are in cache .

If it is the normal of JPA, run the refresh() method of EntityManager by passing the entities to be updated. The values will be reloaded from the database.

If you use some kind of second level cache , you can clear this cache using the following method:

06.02.2014 / 20:50
0

After editing directly into the database, restart your application server and reload the view. As I already experienced this same 'problem', I saw that after restarting the server (in my case Tomcat) the application came to 'see' those changes made. But I'm really looking for a more ideal solution.

    
07.02.2014 / 11:34