-->
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: How to use sessions and caching
PostPosted: Sun Nov 16, 2003 10:16 am 
Newbie

Joined: Thu Nov 13, 2003 1:14 pm
Posts: 18
Location: Leinfelden-Echterdingen, Germany
Hi,

I'm not sure weather I understood all the Hibernate caching and session concepts, maybe someone out there could help me.

As far as I understood, each session has it's own cache so JVM identity is not the same as entity identity.

There are two points I do not understand very well.

1) How to synchronize sessions.
As the same entity is represented by distinct java objects, changes in one session will not affect the other one, which could be exactly what I want as long as I do not flush the first session. But what happens to the second session when the first session is flushed and entities are persisted to the database? Or more general, how can I synchronize two sessions.

2) Top level cache
I read some posts about a factory-level-cache or query-cache which apparently is quite new in Hibernate. I guess this is the answer to my second question. Unfortunately I did not find anything about this cache in the reference manual. Is there any documentation available concerning top level caches? What impact has the use of such an cache on synchronizing sessions and on performance?

Thanks for your help,

Peter


Top
 Profile  
 
 Post subject:
PostPosted: Sun Nov 16, 2003 11:11 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Quote:
1) How to synchronize sessions.


eh?


Quote:
2) Top level cache


Hibernate (1.x-2.0) has a two-level cache architecture:

(1) the session cache (of objects)
(2) the process-level cache of instance data by primary key (provided by JCS)

This well documented in the Hibernate manual and on the Wiki. grep 'JCS'

Hibernate 2.1 has a 2-level+ cache architecture

(1) the session cache (or objects)
(2) the second-level cache of instance data by primary key (might be process-level or clustered)
(3) the query cache for query result sets


Top
 Profile  
 
 Post subject:
PostPosted: Sun Nov 16, 2003 1:12 pm 
Newbie

Joined: Thu Nov 13, 2003 1:14 pm
Posts: 18
Location: Leinfelden-Echterdingen, Germany
Hi,

thanks for the quick answer. I found some details on the two level cache in the docs.

I try to be more clear for my first question: I wondered if any entity that is contained in more than one session at the same time and that is changed in one session will be updated in the other session (if I understood well, I will have two distinct Java objects in such a case). If this update is not done automatically is there a way to "synchronize" sessions manually?

Related to this: if a factory-level-cache is used, does the JCA-cache lead to the equality JVM-identity == persistent identity or are the objects cached in the session level cache distinct from those cached in factory level cache?

Thanks,

Peter


Top
 Profile  
 
 Post subject:
PostPosted: Sun Nov 16, 2003 1:18 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
You don't want the entity updated in the second Session, if it has been changed in the first.

A Session is a unit-of-work, with transaction isolation semantics. You either have to explicitly lock (pessimistic) the entity if you don't want concurrent modifications or use versioning as an optimistic approach, to detect if you have worked with stale data in that second Session. This check happens when you flush/commit the second Session.

Yes, you don't have identical objects also, JVM identity (==) is guaranteed in the scope of a single Session only. This is a good mix.

Thats not only a "Hibernate" approach, but common.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Nov 16, 2003 4:01 pm 
Newbie

Joined: Mon Nov 10, 2003 6:00 am
Posts: 2
It's right that the entity in the second session need no update, if i wan't to make another change to objects. But if i want to read entities for a listing using cursor, then i need a opened session. That's right?
If i flush or close the first session i really want to update an entity in another session and update it.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Nov 16, 2003 4:03 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Please rephrase your question, I didn't get it.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject: One question...
PostPosted: Tue Nov 18, 2003 8:38 am 
Regular
Regular

Joined: Wed Sep 10, 2003 7:09 am
Posts: 63
Hi,

I have a related problem: hibernate is consuming an huge memory space with caches. Is there any way to disable session and/or query cache levels?

Thanks,
Joao Rangel


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 18, 2003 8:51 am 
Regular
Regular

Joined: Tue Aug 26, 2003 7:53 pm
Posts: 66
Location: Lakeland, Florida USA
Quote:
hibernate is consuming an huge memory space with caches


see section 11.3, Managing the session cache

Jeff


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.