-->
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.  [ 7 posts ] 
Author Message
 Post subject: Trouble getting fresh data from DB
PostPosted: Tue Sep 12, 2006 8:54 pm 
Newbie

Joined: Tue Sep 12, 2006 8:38 pm
Posts: 5
Hello,

I am using Hibernate 3. I have a generic type called "Content", and a subtype called "Item". Item is mapped to a database row. Everything starts up fine and I can pull data from the database fine.

I have a seperate system that updates the Database rows. Once this is done, it sends a JMS message to a listener I have that calls:

HibernateUtil.getSessionFactory().evict(Content.class);

The code that reads the content is this:
Session s = HibernateUtil.getSessionFactory().openSession();
Item item = (Item) s.get(Item.class, id);


However, I can NOT get the new database data to get published into my front end.

Details:
I have confirmed the Database row changes manually.
I have confirmed the evict code is being called.
I've tried calling evict(Item.class) and Content.class, I've tried calling s.clear() before calling the "get" method.

I have turned stats on, and am looking at them, and I get the following:
0 cache hits and 0 cache misses, regardless of queries.
x secondary cache hits, and y secondary cache misses. I get a cache miss everytime I update the DB and a JMS message goes out, and it calls the evict, but the data is still old.

I see a SQL query printed by hibernate every time I update the DB and a JMS message goes out, but the data is still old.


Here is my hibernate config:
<hibernate-configuration>

<!-- a SessionFactory instance listed as /jndi/name -->
<session-factory>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost:3306/publish</property>
<property name="connection.username">user</property>
<property name="connection.password">pass</property>
<property name="connection.statement_cache.size">20</property>
<property name="dialect">org.hibernate.dialect.MySQL5Dialect</property>
<property name="show_sql">true</property>
<property name="use_outer_join">true</property>
<mapping resource="mapping.hbm.xml"/>

<!-- cache settings -->
<class-cache class="com.x.y.z.content.Content" usage="read-only"/>

</session-factory>
</hibernate-configuration>


I am calling the query for data through a JSP page running under Tomcat.

Please help!! thanks!!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 13, 2006 10:53 am 
Newbie

Joined: Mon Sep 11, 2006 4:50 pm
Posts: 10
Hi,
Try flushing the session:
Code:
SessionFactory.currentSession().flush();

You can also try to refresh the object to make sure that you get what's in the DB:
Code:
SessionFactory.currentSession().refresh(object);


Good luck!!
Pablo


Top
 Profile  
 
 Post subject: refresh works
PostPosted: Wed Sep 13, 2006 1:20 pm 
Newbie

Joined: Tue Sep 12, 2006 8:38 pm
Posts: 5
flush does not work, but refresh works!! Can you tell me why evict does NOT work? I'd prefer not to have to load the object and call refresh within my JMS notification if I didn't have to. I'd also prefer to be able to rely upon evict and such, especially if I have to clear the cache for an entire object type. Why would evict not work, but refresh would?

Thanks!
N


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 13, 2006 1:33 pm 
Newbie

Joined: Mon Sep 11, 2006 4:50 pm
Posts: 10
I'm glad it helped (can you rate it, so I can keep asking too? ;-) ).
Take a look at this.
http://simoes.org/docs/hibernate-2.1/ap ... lang.Class)
For what I understand, there are two levels of cache, and evict clears only the second. But I'm not sure, I'm also just starting with hibernate.


Top
 Profile  
 
 Post subject: StatelessSession
PostPosted: Wed Sep 13, 2006 1:40 pm 
Newbie

Joined: Tue Sep 12, 2006 8:38 pm
Posts: 5
Also, naturally, if I use a StatelessSession, I do not run into this problem, but then again, I'm not getting any use out of hibernate. :-) If evict is only clears the 2nd level cache, can someone explain how I should clear the 1st AND 2nd level cache at the same time?

Thx,
N


Top
 Profile  
 
 Post subject: Direct Question
PostPosted: Wed Sep 13, 2006 2:22 pm 
Newbie

Joined: Tue Sep 12, 2006 8:38 pm
Posts: 5
When the 2nd level cache results in a "miss", where does it go to get new data? Directly to the DB, or to some other cache level? Thx.


Top
 Profile  
 
 Post subject: Transaction Isolation
PostPosted: Wed Sep 13, 2006 8:46 pm 
Newbie

Joined: Tue Sep 12, 2006 8:38 pm
Posts: 5
Hello,

The solution to my problem was to set the MySQL transaction-isolation level from the default to "READ-COMMITTED". My hibernate cache then successfully pulled the clean data from the database after each evict was triggered.

N>


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 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.