Hello everyone. I´m facing a problem.
I´ve several terminals acessing a database, inserting, updating and loading in queries. The problem is that, if I keeps a session opened and everyone uses this session, I´ve a problem of syncronizing all the data. Then I´m studying a way of use the second level cache.
Each terminal opens a new session and, when it terminates all the work, it closes his session. Doing this:
Code:
Session session = Hibernate.getNewSession();
//do some work
session.close();
Using in this way, I lost the cache mechanism. So, the solution is using the second level cache.
I want to know if these ways are correct, if there are other better ways.... Sugestions are welcome.
I´m thinking in the C3P0 to do a pool mechanism. I´m using aa ehcache with these configurations:
Code:
<defaultCache
maxElementsInMemory="2147483647"
eternal="false"
overflowToDisk="true"
timeToIdleSeconds="120"
timeToLiveSeconds="120"
diskPersistent="false"
diskExpiryThreadIntervalSeconds="120"
/>
From the code, I call in this way:
Code:
static CacheManager manager = null;
//inside static {}
if (manager == null) {
aStr = SystemConfiguration.getInstance().getProperty("hibernateCacheFile" , "../Hibernate/config/ImeEhcache.xml");
//aStr = "../Hibernate/config/ImeEhcache.xml";
try {
manager = CacheManager.create(aStr);
} catch (CacheException e) {
e.printStackTrace();
}
}