No, I do not use the same session. The code is a bit
confusing because I did not include the whole source.
The method getCurrentSession() should be named
getOrCreateCurrentSession(). If you look closely to my
code than you will see that I explicitly close the
current session with closeSession() call therefore
next call to getCurrentSession()  actually creates new
session.

So all the caching happens in the L2 ehcache. 
What is different from your example: 
- I do not use criteria API and issue HQL directly,
- I use H3.1-CVS current

The log of the test looks like this:
0    [main] INFO 
com.sourcelabs.hibernate.tests.HibTest  - Creating new
Hibernate Session: main
4    [main] INFO 
com.sourcelabs.hibernate.tests.HibTest  - Returning
existing session:
SessionImpl(PersistenceContext[entityKeys=[],collectionKeys=[]];ActionQueue[insertions=[]
updates=[] deletions=[] collectionCreations=[]
collectionRemovals=[] collectionUpdates=[]])
Hibernate: select testobj0_.id as id1_, testobj0_.name
as name1_ from test_obj testobj0_ where testobj0_.name
like 'a%'
[EMAIL PROTECTED]
class = class ft945854.TestObj
id = 1
name = aaaaaaaaa
[EMAIL PROTECTED]
class = class ft945854.TestObj
id = 2
name = abbbbbbbb
456  [main] INFO 
com.sourcelabs.hibernate.tests.HibTest  - Closing
Hibernate Session: SessionImpl(<closed>)
456  [main] INFO 
com.sourcelabs.hibernate.tests.HibTest  - Creating new
Hibernate Session: main
[EMAIL PROTECTED]
class = class ft945854.TestObj
id = 1
name = aaaaaaaaa
[EMAIL PROTECTED]
class = class ft945854.TestObj
id = 2
name = abbbbbbbb
465  [main] INFO 
com.sourcelabs.hibernate.tests.HibTest  - Closing
Hibernate Session: SessionImpl(<closed>) 

--- Patrick Casey <[EMAIL PROTECTED]> wrote:

> 
>       You're using the same session though aren't you in
> that example? So
> you're really using the first level cache, not the
> second level cache. Or
> are you creating a fresh session with
> currentSession?
> 
>       Try replacing your s = currentSession() calls with:
> 
>       Session s = fSessionFactory.openSession();
> 
>       And see if it still works for you. I'm suspicious
> that you're just
> closing and then reopening the same session in the
> sample code you have
> below (maybe I'm wrong though).
> 
>       --- Pat
> 
> 
> > -----Original Message-----
> > From: Konstantin Ignatyev
> [mailto:[EMAIL PROTECTED]
> > Sent: Saturday, September 24, 2005 11:30 PM
> > To: Tapestry users
> > Subject: RE: Hibernate session model
> > 
> > And that is not what I see, cacheable statement
> gets
> > executed only once and for second query there are
> no
> > trips to database, none.
> > My code
> > 
> > public void test(Session s) throws Exception {
> >         s = currentSession();
> >         queryCacheableObject(s);
> >         closeSession();
> > 
> >         s = currentSession();
> >         queryCacheableObject(s);
> >     }
> > 
> >     private void queryCacheableObject(Session s) {
> >         Query query = s.createQuery("from TestObj
> t
> > where t.name like 'a%'");
> >         query.setCacheable( true );
> >         List objects = query.list();
> >         print( objects);
> >     }
> > 
> > 
> >     public static void main(String[] args) {
> >         Test945854 t = new Test945854();
> >         t.executeTests();
> > 
> >     }
> > 
> > mapping:
> > <class
> >       name="TestObj"
> >       table="test_obj"
> >       dynamic-update="true"
> >       >
> >       <cache usage="read-write" />
> > 
> >       <id
> >       name="id"
> >       type="java.lang.Integer"
> >       unsaved-value="null"
> >       >
> >       <generator class="assigned">
> >       </generator>
> >       </id>
> > 
> >       <property
> >       name="name"
> >       type="java.lang.String"
> >       />
> >   </class>
> > 
> > configuration
> > 
> >  <property
> >
> name="hibernate.cache.enable_cache">true</property>
> > <property
> >
>
name="hibernate.cache.use_query_cache">true</property>
> > <property
> >
> name="hibernate.statement_cache.size">25</property>
> > <property name="hibernate.cache.provider_class">
> > org.hibernate.cache.EhCacheProvider</property>
> > 
> > --- Patrick Casey <[EMAIL PROTECTED]> wrote:
> > 
> > >
> > >   You know, that's just not what I'm seeing. I
> even
> > > wrote a little
> > > test app.
> > >
> > >   Criteria c  =
> > >
> HibHelper.getSession().createCriteria("core.User");
> > >   c.setCacheable(true);
> > >   List l = c.list();
> > >   // the above executes a single query to fill
> the
> > > cache
> > >   // I get one and only one query in my SQL trace
> > >   c =
> > >
> >
>
HibHelper.getTransientTempSession().createCriteria("core.User");
> > >   // a new criteria on a new session
> > >   c.setCacheable(true);
> > >   l = c.list();
> > >   // the above should hit the cache
> > >   // lo and behold, we get 1,000 individual
> selects
> > >   // as every single key from the original select
> is
> > > iteratively
> > >   // fetshed one at a time
> > >
> > >   Perhaps I have something configured wrong?
> > >
> > >   The point in my mapping where I enable the
> cache:
> > >
> > >   <class name="core.Person" table="person"
> > > dynamic-update="true">
> > >           <cache usage="read-write" />
> > >           /// blah blah blah
> > >   </class>
> > >
> > >   The point in my hibernate configuration where I
> > > enable ehcache:
> > >
> > >   <property
> > >
> >
>
name="hibernate.cache.use_query_cache">true</property>
> > >
> > >   My ehcache.xml where I set a nice spiffy
> default
> > > cache:
> > >
> > > <defaultCache
> > >         maxElementsInMemory="10000"
> > >         eternal="false"
> > >         timeToIdleSeconds="1200"
> > >         timeToLiveSeconds="1200"
> > >         overflowToDisk="false"
> > >         diskPersistent="false"
> > >         diskExpiryThreadIntervalSeconds="120"
> > >         />
> > >
> > >   Is there some additional parm I have to set to
> > > enable the L2 object
> > > cache here? Because from what I'm seeing here,
> the
> > > keys are getting cached,
> > > but the object themselves are not, leading to
> the
> > > aforementioned 1000
> > > selects by key (which is about 200X worse than
> just
> > > one massive select).
> > >
> > >   --- Pat
> > >
> > > > -----Original Message-----
> > > > From: Konstantin Ignatyev
> > > [mailto:[EMAIL PROTECTED]
> > > > Sent: Saturday, September 24, 2005 8:06 PM
> > > > To: Tapestry users
> > > > Subject: RE: Hibernate session model
> > > >
> > > > Query cache is slightly different thing than
> > > > Hibernate's 2L cache.
> > > > L2 cache holds objects and L2 cache will
> supply
> > > > objects by keys in Query cache.
> > > >
> > > > --- Patrick Casey <[EMAIL PROTECTED]>
> wrote:
> > > >
> > > > >
> > > > >       Henri,
> > > > >
> > > > >       Where are you getting your information
> from?
> > > > > According to my copy of
> > > > > Hibernate in action (pp 291 Secion 7.6.3).
> > > > >
> > > > >       "Note that the query cache does *not* cache
> the
> 
=== message truncated ===


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to