views:

206

answers:

5

I am programming a JSP/JSF Web application and currently using Hibernate (and MySQL) libraries. When I update data using my running application everything is working fine.

Example : I modify a customer information

Although if I change data manually or add an entry in MySQL manually, the change will not be effective on my application side.

Problem : Each time, I have to reload the application.

Anyone can understand my problem and find a rapid solution ?

A: 

Probably Hiberante cache is enabled and needs to be reload the rows/object.

Or you should update/insert data via Hibernate as well.

Alexandru Luchian
Well the problem is we have a local application and a web application that uses the same database. If I make a change in the database using the software application, the data cannot be updated within the web application only if the page is reloaded. (The whole application has to be reloaded.) I didnt find any configuration that Ive made abot hibernate cache.
wiooz
+1  A: 

Are you using second level cache in your web application? If so, your options are:

  1. Use clustered cache (see above link for options) and remotely invalidate it when your local application makes changes to the database.
  2. Expose an API (web service or even basic URL) in your web app that you'll have to invoke (manually or via your "local" application) to invalidate the cache. Basically, same as #1 but more work :-) so only use if #1 is not applicable.

If you're not using 2nd level cache but experiencing the issue you've described, that means you're holding on to your Session for way too long. Sessions should generally be short-lived.

ChssPly76
Thank you for the information. I think I am not using any cache in this application. When I show different payments for example, it should only reload the data when I reload the page...Session session = SessionFactoryUtil.getInstance().openSession(); SQLQuery query = session.createSQLQuery("SELECT * FROM factures INNER JOIN paiements ON paiements.id_facture = factures.id_facture WHERE factures.id_membre = " + this.membre.getIdMembre());query.addEntity(Paiements.class).addEntity(Factures.class);List paiements = query.list();session.close();
wiooz
Are you holding on to query results within your page (session, etc...) perhaps? Enable hibernate SQL debug (http://docs.jboss.org/hibernate/stable/core/reference/en/html/session-configuration.html#configuration-optional) and check that query is indeed executed every time you hit the page.
ChssPly76
A: 

I'm not sure how you've configured your Hibernate sessions, but some configurations require that you flush your session in addition to closing it (e.g., sessions that are able to be disconnected from the underlying JDBC connection to the DB). So in a comment reply, you said that you end your work with session.close(); -- try doing:

session.flush();
session.close();

instead and see if this fixes what you're seeing.

Otherwise, I'd look to verify that you're really not using a second-level cache... explicitly disable it in your Hibernate configuration, setting hibernate.cache.provider_class to org.hibernate.cache.NoCacheProvider.

delfuego
OP's running a query; there's nothing to flush. In that same spirit, queries must be explicitly marked as cacheable; having / not having 2nd level cache provider configured won't make a difference without that.
ChssPly76
A: 

Try this:

Session session = SessionFactoryUtil.getInstance().openSession();
session.clear();

Alternatively, you can explicitly use a StatelessSession, which has no caching. Details can be found here:

https://www.hibernate.org/hib_docs/v3/api/org/hibernate/StatelessSession.html

Marc Paradise
A: 

Reading the other answers and the comments it's really strange. Can you confirm that you close the Hibernate session at least once every page calls? Are you sure that the other application modifying the database really commits the changes?

Damien B