-->
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.  [ 4 posts ] 
Author Message
 Post subject: Clear Hibernate session cache before Query?
PostPosted: Wed Jul 27, 2016 11:44 am 
Newbie

Joined: Thu Aug 29, 2013 6:43 am
Posts: 7
My website uses a combination of Django + Java apps to function. For this particular problem, a record is deleted from the DB via a TastyPie resource DELETE operation. A Django signal post_delete handler is invoked, which submits an HTTP DELETE request to Jetty running in the Java app. The Java app then performs a query using Hibernate.

What appears to be happening is that Django thinks the record was deleted. I invoke this code in the post_delete signal handler:

DynamicVolume.objects.filter(user=instance.user).count()

Which returns ZERO.

However, the Java app thinks the record still exists unless I make it sleep for several seconds before asking Hibernate to query the DB.

I've tried forcing Hibernate to clear its cache with no success. Any suggestions appreciated.

Thanks


Top
 Profile  
 
 Post subject: Re: Clear Hibernate session cache before Query?
PostPosted: Wed Jul 27, 2016 4:04 pm 
Newbie

Joined: Thu Aug 29, 2013 6:43 am
Posts: 7
I believe Django might be at fault here.


Top
 Profile  
 
 Post subject: Re: Clear Hibernate session cache before Query?
PostPosted: Thu Jul 28, 2016 3:15 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
That's how transaction isolation works.

Django uses its own database connection and so it can read its own writes. On the other hand, Hibernate uses a separate database connection, and if Django has not got the chance to commit, Hibernate is not going to see any change that Django has issued. This is the expected behavior for any isolation level that is greater or equal to READ COMMITTED).

The solution is simple. You just have to commit the transaction in Django. If the Hibernate Session has already cached the entity that you modify in Django, you'll have to use refresh.


Top
 Profile  
 
 Post subject: Re: Clear Hibernate session cache before Query?
PostPosted: Thu Jul 28, 2016 6:43 am 
Newbie

Joined: Thu Aug 29, 2013 6:43 am
Posts: 7
Thanks. I think Django has performed the write, but it is inside a transaction so it hasn't been committed. The Java process can allow a 5s delay before reading the database again so I can do that for now. It's not a big deal and doesn't affect the functionality even though technically it's a "hack".

Thanks again.


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