<html>
<head>
<style>
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
FONT-SIZE: 10pt;
FONT-FAMILY:Tahoma
}
</style>
</head>
<body class='hmmessage'>
<FONT color=#0000ff><FONT size=2>
<FONT color=#000000>Hello to all, </FONT><BR>
<FONT color=#000000>I am practicing with Hibernate and I have a problem with the management of the caching. Excuse my ignorance.</FONT><BR>
<FONT color=#000000>The simple program that I have developed in order to try the caching's functionality gives me </FONT><BR>
<FONT color=#000000>an output that I can't understand. The problem is that when the program is using the</FONT><BR>
<FONT color=#000000>data, which is captured from the DB through the funzione load(), it behaves as if the data </FONT><BR>
<FONT color=#000000>it was not in cache.Studying the handbook of Hibernate I saw that the data is inserted </FONT><BR>
<FONT color=#000000>in cache every time is executed the load(), and that it is possible to use the function </FONT><BR>
<FONT color=#000000>contain() in order to see if this data is effectively in cache, like it really ensues.</FONT><BR>
<FONT color=#000000></FONT> <BR>
<FONT color=#000000>This is the code fragment:</FONT><BR>
<FONT color=#000000></FONT> <BR>
<FONT color=#000000>private void spatialFactory(String[] args){</FONT><BR>
<FONT color=#000000></FONT><BR>
<FONT color=#000000> config = new Configuration();</FONT><BR>
<FONT color=#000000></FONT><BR>
<FONT color=#000000> config.configure(); </FONT><BR>
<FONT color=#000000> config.addClass(MultiPolygonEntity.class);</FONT><BR>
<FONT color=#000000></FONT><BR>
<FONT color=#000000> Settings settings = config.buildSettings();</FONT><BR>
<FONT color=#000000> System.out.println("Generating Data for Dialect: "+ settings.getDialect().getClass().getName()); </FONT><BR>
<FONT color=#000000></FONT><BR>
<FONT color=#000000> SessionFactory factory = config.buildSessionFactory();</FONT><BR>
<FONT color=#000000> Session session = factory.openSession();</FONT><BR>
<FONT color=#000000></FONT><BR>
<FONT color=#000000> Transaction tx = null;</FONT><BR>
<FONT color=#000000></FONT><BR>
<FONT color=#000000> try{</FONT><BR>
<FONT color=#000000> tx = session.beginTransaction();</FONT><BR>
<FONT color=#000000> if(args[0].equals("store_mulpol")){</FONT><BR>
<FONT color=#000000></FONT><BR>
<FONT color=#000000> geom = createMPolygon(); </FONT><BR>
<FONT color=#000000></FONT><BR>
<FONT color=#000000> for(long i=1; i<=gid; i++){</FONT><BR>
<FONT color=#000000></FONT><BR>
<FONT color=#000000> MultiPolygonEntity MPolygon = (MultiPolygonEntity)session.load(MultiPolygonEntity.class,i);</FONT><BR>
<FONT color=#000000></FONT><BR>
<FONT color=#000000> Geometry the_geom = MPolygon.getGeometry();</FONT><BR>
<FONT color=#000000></FONT><BR>
<FONT color=#000000> if(geom.intersects(the_geom))throw new Exception();</FONT><BR>
<FONT color=#000000> }</FONT><BR>
<FONT color=#000000></FONT><BR>
<FONT color=#000000> MultiPolygonEntity MultiPolygon = new MultiPolygonEntity(gid+1,344,"Polygon",geom);</FONT><BR>
<FONT color=#000000> session.save(MultiPolygon); </FONT><BR>
<FONT color=#000000></FONT><BR>
<FONT color=#000000> tx.commit();</FONT><BR>
<FONT color=#000000></FONT><BR>
<FONT color=#000000> }</FONT><BR>
<FONT color=#000000> }</FONT><BR>
<FONT color=#000000> ...</FONT><BR>
<FONT color=#000000></FONT> <BR>
<FONT color=#000000>}</FONT><BR>
<FONT color=#000000></FONT> <BR>
<FONT color=#000000> </FONT><BR>
<FONT color=#000000>In the moment in which the program is executed, the instruction ' Geometry the_geom = MPolygon.getGeometry();' in order to use </FONT><BR>
<FONT color=#000000>a property of the loaded object (geometry exactly), the output is the following:</FONT><BR>
<FONT color=#000000></FONT> <BR>
<FONT color=#000000>22:22:27,975 DEBUG MemoryStore:138 - Cache_SpatialCache: Cache_SpatialMemoryStore miss for hsp.MultiPolygonEntity#1</FONT><BR>
<FONT color=#000000>22:22:27,975 DEBUG Cache:661 - Cache_Spatial cache - Miss</FONT><BR>
<FONT color=#000000>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=?</FONT><BR>
<FONT color=#000000>22:22:28,053 DEBUG MemoryStore:138 - Cache_SpatialCache: Cache_SpatialMemoryStore miss for hsp.MultiPolygonEntity#1</FONT><BR>
<FONT color=#000000>22:22:28,053 DEBUG Cache:661 - Cache_Spatial cache - Miss</FONT><BR>
<FONT color=#000000></FONT> <BR>
<FONT color=#000000>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.</FONT><BR>
<FONT color=#000000>Do you know the reason ?</FONT><BR>
<FONT color=#000000>I have shaped Hibernate with EhCacheProvider and in the rows of mapping I have set up one cache Read-Write.</FONT><BR>
<FONT color=#000000></FONT> <BR><FONT color=#000000>
thanks,<BR>
<BR>
Tobia<BR></FONT></FONT></FONT><br /><hr />Se sei stanco dei soliti auguri, scarica GRATIS le emoticon di Natale! <a href='http://www.emoticons-livemessenger.com/pages/msnitnatale/' target='_new'>Windows Live Messenger</a></body>
</html>