-->
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.  [ 8 posts ] 
Author Message
 Post subject: Hibernate session cache synchronization
PostPosted: Mon Nov 29, 2004 8:55 am 
Newbie

Joined: Mon Nov 29, 2004 8:15 am
Posts: 8
Hi, this is my first post.

I'm having problems with hibernate session cache in an desktop application that access to a hibernate/web services based server. The server creates a session for each client. When the clients exits the desktop applications then the his session is closed.

The typical scenario is:

- Client B performs a query over Entity E1. Entity E1 gets cached on its session cache.
- Client A performs an update/save/delete operation on Entity E1
- Client B tries to load E1, but because its preloaded in its local session cache, then an obsolete instance of E1 is returned.

So, what is the best approach to synchronize the different session caches ?

I have tried to perform refresh operations, buth when E1 have child collections I have having problems with delete operations. For example if E1 have a 1x1 relation with an E2 instance, and E2 gets deleted, after refresh() the changes aren't reflected.

I have also tried to evict instances, but it seems that a evict recursively is necessary, because several exceptions are thrown saying that object instances already exists.

In google I have found the Hibernate team recommending to use clear() operation but this seems a drastic solution to a common problem.

Any ideas/suggerences ?

Thanks for your time.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 29, 2004 9:03 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
why don't you commit and close your session when you are done and then open a session again when needed ?

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 29, 2004 9:34 am 
Newbie

Joined: Mon Nov 29, 2004 8:15 am
Posts: 8
Because the operation of opening a new session takes several seconds because hundreds of SQL operations are performed.

After each transaction I disconnect the session. When the user request another transaction I connect again to the same session. This is really fast.

Kind regards,
Martin


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 29, 2004 9:38 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
FlushMode.NEVER


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 29, 2004 9:40 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
I'll advice you to read the chapters about session handling in the Hibernate book - there is a reason why hundreds of sql is performed (consistency/integrity!); but you might not need them - but that is something you can decide not I ;)

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 29, 2004 9:53 am 
Newbie

Joined: Mon Nov 29, 2004 8:15 am
Posts: 8
I don't know if I'm not explaining very well. That wouldn't be strange, and I'm sure that my poor English level doesn't helps.

I have read hibernate help, patterns and Hibernate in Action book. And I think that they recommends do not close the session, they recommend disconnect/connect operations to optimize JDBC performance. But, maybe I'm wrong.

From Hibernate API: public void setFlushMode(FlushMode flushMode): Set the flush mode. The flush mode determines at which points Hibernate automatically flushes the session. For a readonly session, it is reasonable to set the flush mode to FlushMode.NEVER at the start of the session (in order to achieve some extra performance).

My application does *a lot* of creation/update/delete operations. I'm not sure that setting FlushMode to NEVER will help me.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 29, 2004 9:56 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Read chapters 4, 5 and 8 again, in that order.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 30, 2004 3:02 am 
Newbie

Joined: Mon Nov 29, 2004 8:15 am
Posts: 8
Thanks Christian, I'll take your advice in mind and I'll re-read those chapters.

I hope this advice do not be like the "use FlushMode.NEVER" previous, for an app that wish to modify rows in the database.

Anyway, I have solved my problem using clear() method, but I think that this isn't satisfactory enough. Why ? It's easy, my users all have a view from a repository, for example:

A
|
--B
| --B1
| --B2
--C

If the user refresh node B2, clear() will remove from the caché nodes A,B,B1 and C. Later access to this nodes will suppose extra database hits.

I'm going to use some second level caché like EHCache to minimize this database hits.

Both, thanks for your help, in spite of little hostility in the replies it helps me.


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