-->
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.  [ 6 posts ] 
Author Message
 Post subject: Hibernate caching problems
PostPosted: Wed Nov 19, 2003 8:00 am 
Regular
Regular

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

I've been using Hibernate for 2,5 months (currently using 2.1beta6) and when i was making carge tests to my application database, i got several memory problems. I run some memory profiles programs and I checked that The problem is related with Hibernate cache.

As long as I understood, Hibernate has 3 cache levels (correct me if i'm wrong):
- JCS cache, which is shared by all hibernate sessions;
- Session cache;
- Query cache.

JCS cache is optional, and is not causing any problems.

The problem is releated with session and query caches. When I load an object I do the following code:

private Object obj;
obj = (Object) session.load(Object.class, 1);

The loaded object will be duplicated in memory: in variable obj, and in Hibernate internal session cache. If insted of 1 object, I loaded a large number of objects with a large number of associations each one, I will run out of memory.

As a solution, I try to evict the object after loading it, but this as two problems:
- Evict doesn't work beacuse the memory never decreases;
- If it worked, it still would be a bad solution, because I was loading an object in cache to download it later. It's an waste of processor resources.

If I load an object by query, it's worst, beacuse that object and a few others will be loaded in query caches, and can not be evicted. Session.clear() doesn't work too, beacuse the memory never decreases.

In the worst case, if I load an object individualy, and next, load it within a collection, I will have the object replicated 3 times in memory: my java variable, hibernate session cache and hibernate query cache.

Other thing I don't understand is the diference between queries and criteria queries, in the cache context. Is there any diference between them? Or they both use cache in the same way?

I would like to NOT use any session and/or query cache. Is it possible? Hibernate cache it doesn't improve performance on my application, and it's giving me a lot of problems.

I read several posts about cache system and I saw that there are another users with the same problems, but the questions were spread by many posts and the answers were incomplete. I tryed to join everything in a same (long) post, and I would like to ask for hibernate team assistence.

Thanks in advance,
Joao Rangel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 19, 2003 8:03 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
You should be closing and dereferencing the Session at the end of a transaction. Then the session cache will be garbage collected.


Top
 Profile  
 
 Post subject: Session.close doesn't work
PostPosted: Wed Nov 19, 2003 8:10 am 
Regular
Regular

Joined: Wed Sep 10, 2003 7:09 am
Posts: 63
Your right, but i tried to do that, and session.close() did not release any memory either. I forgot to mention it in the previous post.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 19, 2003 8:13 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Then I don't think that your memory leak is in Hibernate :)

I suggest you inspect the source of session.close() to confirm that there is no possibility of a leak.


Top
 Profile  
 
 Post subject: Restarting often and using C3P0?
PostPosted: Wed Nov 19, 2003 1:03 pm 
Regular
Regular

Joined: Sun Sep 21, 2003 11:43 pm
Posts: 85
Location: Massachusetts
Are you restarting often and using C3P0 connection pooling with Hibernate? I posted a week or two back how I found that the version shipped with Hibernate has no way to close the connection pool so when you restart, it seems to get orphaned and hibernate appears to start up a new one ... thereby eating memory. I still have some memory problems in my Tomcat/Hibernate/Struts1.1 application but, for the life of me, I can't find them.

Regards,
David


Top
 Profile  
 
 Post subject: I have the same problem
PostPosted: Mon Jan 05, 2004 12:34 am 
Newbie

Joined: Mon Jan 05, 2004 12:00 am
Posts: 2
I have the same problem, when I executed a query via a session,I got a list of my object, then I closed the session, I found something still referenced by the sessionFactory (the sessionFactory is a static variable of the type SessionFactory ),I want to know how to resovle the problem?


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