-->
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.  [ 2 posts ] 
Author Message
 Post subject: HIBERNATE CACHING
PostPosted: Thu Jan 03, 2008 2:06 pm 
Newbie

Joined: Thu Jan 03, 2008 2:00 pm
Posts: 1
Hello to all,

I am practicing with Hibernate and I have a problem with the management of the caching.
The simple program that I have developed in order to try the caching's functionality gives me
an output that I can't understand. The problem is that when the program is using the
data, which is captured from the DB through the funzione load(), it behaves as if the data
it was not in cache.Studying the handbook of Hibernate I saw that the data is inserted
in cache every time is executed the load(), and that it is possible to use the function
contain() in order to see if this data is effectively in cache, like it really ensues.

This is the code fragment:

private void spatialFactory(String[] args){

config = new Configuration();

config.configure();
config.addClass(MultiPolygonEntity.class);

Settings settings = config.buildSettings();
System.out.println("Generating Data for Dialect: "+ settings.getDialect().getClass().getName());

SessionFactory factory = config.buildSessionFactory();
Session session = factory.openSession();

Transaction tx = null;

try{
tx = session.beginTransaction();
if(args[0].equals("store_mulpol")){

geom = createMPolygon();

for(long i=1; i<=gid; i++){

MultiPolygonEntity MPolygon = (MultiPolygonEntity)session.load(MultiPolygonEntity.class,i);

Geometry the_geom = MPolygon.getGeometry();

if(geom.intersects(the_geom))throw new Exception();
}

MultiPolygonEntity MultiPolygon = new MultiPolygonEntity(gid+1,344,"Polygon",geom);
session.save(MultiPolygon);

tx.commit();

}
}


In the moment in which the program is executed, the instruction ' Geometry the_geom = MPolygon.getGeometry();' in order to use
a property of the loaded object (geometry exactly), the output is the following:

22:22:27,975 DEBUG MemoryStore:138 - Cache_SpatialCache: Cache_SpatialMemoryStore miss for hsp.MultiPolygonEntity#1
22:22:27,975 DEBUG Cache:661 - Cache_Spatial cache - Miss
Hibernate: select multipolyg0_.gid as gid0_0_, multipolyg0_.code as code0_0_, multipolyg0_.name as name0_0_, multipolyg0_.the_geom as the4_0_0_ from spatial multipolyg0_ where multipolyg0_.gid=?
22:22:28,053 DEBUG MemoryStore:138 - Cache_SpatialCache: Cache_SpatialMemoryStore miss for hsp.MultiPolygonEntity#1
22:22:28,053 DEBUG Cache:661 - Cache_Spatial cache - Miss

To me it seems that, although the load() is executed, the data is not found in cache, even if the use of the function contain() results present.
Do you know the reason ?

I have shaped Hibernate with EhCacheProvider and in the rows of mapping I have set up one cache Read-Write.


Top
 Profile  
 
 Post subject: cache
PostPosted: Thu Jan 03, 2008 3:19 pm 
Expert
Expert

Joined: Mon Nov 26, 2007 2:29 pm
Posts: 443
If I understood your example correctly, you are always loading a different MultiPolygon, therefore, the cache can't help you.
As far as I know, the cache is only useful upon repeated calls to "load" on the same object.

_________________
Gonzalo Díaz


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