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.  [ 1 post ] 
Author Message
 Post subject: Entity fetching behaviour with secong level cache
PostPosted: Fri Jun 06, 2014 3:56 am 

Joined: Fri Jun 06, 2014 3:31 am
Posts: 1
Hi all,

I am using hibernate 4.3.5 as JPA 2.1 provider.

I have a following problem: I want to use 2nd level cache but I want hibernate to reuse the data in the cache as much as possible. The reason for this is that I want to fetch large amounts of data from DB in the form of entities that are kept in memory longer than the hibernate session lasts (and I don't want to use extended persistence contexts). It would be very useful if I the data from the cache got reused instead of allocating new objects. For example if data for entity user(id:5) exists in the 2nd level cache, it would be desireable for query that returns corresponding row from the database to return the user object that has the same string object for user name that currently resides in the second level cache so that garbage collector can quickly remove the data from result set and free up memory.

I understand that this may not always be possible if we want to keep the cache updated, but I have only one application that uses the DB so there's no harm done. So far, I've investigated when exactly does hibernate reuse data from 2nd level cache, and the behavoiur seems quite erratic. First, it naturally reuses the data when I call EntityManager.find(), and that's fine. But when I run queries things get really complicated. The behavoiur seems to vary greatly depending on whether I use join fetch or not, depending on the type of fetch and so on.

So does anyone know the exact rules/configurations that govern the way hibernate reuses (or doesn't reuse) the data from 2nd level cache when fetching query results? Also is there a configuration that can help me tune this behavoiur to my needs? Also let me point out that using query cache is also out of the question because of it's tendency to pile up large amounts of data and to get invalidated quiclky.

Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.