-->
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: Not able to use Second level cache
PostPosted: Mon Mar 08, 2004 8:39 am 
Newbie

Joined: Wed Jan 21, 2004 5:09 am
Posts: 11
Hi.

Considering the following example, I'm not sure second level cache is working :

...
Session session1 = sessionFactory.openSession();
Session session2 = sessionFactory.openSession();

Long id = new Long(1);
MyObject obj1 = (MyObject) session1.get(MyObject.class, id);
MyObject obj2 = (MyObject) session2.get(MyObject.class, id);
...

each session returns an object.
But using
hibernate.cache.use_query_cache=true

I can see 2 sql request.
I hoppend that second level cache (jvm) will allow the second request to not occur.

I tried with HashtableCache and EHCache on hibernate 2.1.2

I tried many ways
- with and without closing session1 before using session2,
- with and witjout transactions,
- with and without hibernate.cache.use_query_cache=true (Also, it seems that we MUST use it. Isn't it optionnal ?)

By the way, I saw that the result is different if I provide my own connections to the session. When I do this, they are timestamps that are always <0 (Generated by class Timestamper ...). Well, I'm not sure it's a problem ...

Thanks in advance for any help.

Mike


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 08, 2004 8:45 am 
Regular
Regular

Joined: Mon Nov 24, 2003 6:36 pm
Posts: 105
How about your mapping files? Do they decalare that this object should be cached?

eg:
<cache usage="read-only"/>
In the mapping file for "MyObject"


James


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 08, 2004 4:06 pm 
Newbie

Joined: Wed Jan 21, 2004 5:09 am
Posts: 11
Quote:
<cache usage="read-only"/>


sorry, I forgot to say that I already have put this line in my mapping ...


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 08, 2004 4:08 pm 
Newbie

Joined: Wed Jan 21, 2004 5:09 am
Posts: 11
and it don't works ...

(I'm not sure my previous post was really clear ...)


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 08, 2004 8:33 pm 
Regular
Regular

Joined: Mon Nov 24, 2003 6:36 pm
Posts: 105
just a bit of a guess- I'm using sess.load, not sess.get. Possibly hibernate doesn't look in cache on get?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 09, 2004 2:29 am 
Newbie

Joined: Wed Jan 21, 2004 5:09 am
Posts: 11
jlawmi wrote:
just a bit of a guess- I'm using sess.load, not sess.get. Possibly hibernate doesn't look in cache on get?


I tried get and load.
load is used to return a proxy if possible.

In your case, do you have cache ?
On session, cache works very well : 2 get with the same id on the same session returns the same object and execute only one sql query.
But do you see that the samething on 2 different sessions is true ???
(At least, it must run just one query but it seems that it will not return the same object instance ...)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 09, 2004 5:51 am 
Newbie

Joined: Wed Jan 21, 2004 5:09 am
Posts: 11
It finally works by changing

Quote:
Session session1 = sessionFactory.openSession();
Session session2 = sessionFactory.openSession();

Long id = new Long(1);
MyObject obj1 = (MyObject) session1.get(MyObject.class, id);
MyObject obj2 = (MyObject) session2.get(MyObject.class, id);


to

Quote:
Session session1 = sessionFactory.openSession();

Long id = new Long(1);
MyObject obj1 = (MyObject) session1.get(MyObject.class, id);

Session session2 = sessionFactory.openSession();
MyObject obj2 = (MyObject) session2.get(MyObject.class, id);


ie opening the second session AFTER the object was put in jvm cache.

I have another problem :

If I change the working example, opening sessions with

Session session2 = sessionFactory.openSession(c);
..
Session session1 = sessionFactory.openSession(c);

(I provide a connection)

It stop working.


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.