-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Database changes not being detected
PostPosted: Tue Mar 11, 2008 12:13 pm 
Newbie

Joined: Tue Mar 11, 2008 11:30 am
Posts: 2
I have a database that is being acted on by several "agents". The user interface is a fairly simple web application. My problem is that changes made by other processes are not reflected in the web application.

That is to say, any changes made to the database after the webapp is initialized fail to appear on it.

Initially I thought it might be the first level cache. That the sessions were being reused. However I quickly ruled that out as each request ended with the hibernate session being properly closed and a new one being created for subsequent requests.

That led me to the second level cache which (as I understand) should be disabled by default. To further guard against this I added the following to my hibernate.cfg.xml:

<property name="cache.use_second_level_cache">false</property>
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>

just to make it absolutely clear. No change.

I then turned my attention to Tomcat. Figuring this might be some weirdness to do with it I created a very simple Test program

Code:
         PublicationDAO pDAO = new PublicationDAO();
         
         List<Publication> list = (List<Publication>)pDAO.findAll();
         
         for(Publication p : list){
            System.out.println(p.getName());
         }
         
         HibernateSessionFactory.closeSession();
         
         Thread.sleep(5000);


Needless to say, the problem persisted. Turning on show_sql caused an SQL statement to be printed out for each iteration but any changes I made to the database failed to show up.

The HibernateSessionFactory is a (mostly) auto generated object (by MyEclipse) that follows the Thread Local Session pattern.

It was only when I added code to rebuild the SessionFactory it used (kept as a static variable) before getting a new session that the Test program started to reflect changes in the database as they occurred. However, repeatedly rebuilding the SessionFactory seems a sub-optimal solution (to say the least).

Unfortunately I'm now entirely out of ideas as to what may be causing this and would greatly appreciate any help and thoughts you may have.

Hibernate version: 3.1.3

Name and version of the database you are using: MySQL 5


Last edited by ibwolf on Wed Mar 12, 2008 4:55 am, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 11, 2008 10:33 pm 
Red Hat Associate
Red Hat Associate

Joined: Mon Aug 16, 2004 11:14 am
Posts: 253
Location: Raleigh, NC
If the SQL is hitting the database then there is only one culprit I can think of -- Transactions. Either a) the other processes aren't committing data or b) your test program is somehow running in the context of a single uncommitted transaction and your database is isolating it.

Try wrapping your Hibernate code in session.getTransaction().begin() / .commit(). This will ensure that repeated reads are in new transactions. Of course it's also possible that you're mistakenly hitting the wrong DataSource :)

_________________
Chris Bredesen
Senior Software Maintenance Engineer, JBoss


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 12, 2008 4:48 am 
Newbie

Joined: Tue Mar 11, 2008 11:30 am
Posts: 2
cbredesen wrote:
If the SQL is hitting the database then there is only one culprit I can think of -- Transactions. Either a) the other processes aren't committing data or b) your test program is somehow running in the context of a single uncommitted transaction and your database is isolating it.

Try wrapping your Hibernate code in session.getTransaction().begin() / .commit(). This will ensure that repeated reads are in new transactions. Of course it's also possible that you're mistakenly hitting the wrong DataSource :)


That worked. Seems like b) was the culprit. Thanks for the help.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.