-->
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.  [ 3 posts ] 
Author Message
 Post subject: using session cache and/or second level cache
PostPosted: Thu Jan 19, 2006 12:53 pm 
Beginner
Beginner

Joined: Mon Oct 03, 2005 5:13 pm
Posts: 30
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();
         }
      }


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 19, 2006 5:41 pm 
Newbie

Joined: Thu Sep 02, 2004 2:31 pm
Posts: 12
You don't have to use the EhCache API directly, just configure Hibernate correctly and it will manage the interaction with EhCache for you.

http://www.hibernate.org/hib_docs/v3/re ... ance-cache

Also notice the section on the query cache. Enable this to cache the results of your queries (in addition to just the entities themselves).


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 19, 2006 7:56 pm 
Expert
Expert

Joined: Tue Nov 23, 2004 7:00 pm
Posts: 570
Location: mostly Frankfurt Germany
May be a hint to you
a cache like EHcache is shared across a JVM.

I do not consider sharing a session by multiple threads as "stable". As somewhere in the reference " a session is a short living ..."

Configure a cache withe cache settings.
In your mapping add the cache tag.
eg
Code:
  <class name="Developer" table="tdeveloper">
  <cache usage="read-write" />

your cache is extremely large. When each object has only 1 Byte, your cache will have a total of 2 GB RAM.

When I serialize a simple class, I get a size of about 250 Bytes.

Regards Sebastian

_________________
Best Regards
Sebastian
---
Training for Hibernate and Java Persistence
Tutorials for Hibernate, Spring, EJB, JSF...
eBook: Hibernate 3 - DeveloperGuide
Paper book: Hibernate 3 - Das Praxisbuch
http://www.laliluna.de


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