Hello to all,
I am practicing with Hibernate and I have a problem with the management of the caching. Excuse my ignorance.
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.
 
thanks,
 
Tobia


Se sei stanco dei soliti auguri, scarica GRATIS le emoticon di Natale! Windows Live Messenger