-->
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.  [ 2 posts ] 
Author Message
 Post subject: Cache not working with annotations
PostPosted: Thu May 11, 2006 5:22 am 
Beginner
Beginner

Joined: Tue Nov 22, 2005 5:33 am
Posts: 31
I have a very simple application where I am trying to enable second level cache, but can't get it to work.


I have a main class which look like this:
------------------------------------
public static void main(String[] args) {
Session session = HibernateUtil.getCurrentSession();
HibernateUtil.beginTransaction();
for (int i = 0; i < 5; i++) {
Timer timer = new Timer("Get players");
List list = session.createCriteria( PlayerEntity.class )
.add(Restrictions.eq( "nickName", "homer" ))
.setCacheable(true).list();
timer.done();
}
HibernateUtil.rollbackTransaction();

}
------------------------------------
The class PlayerEntity looks like this:
------------------------------------
@Entity
@Cache(usage=CacheConcurrencyStrategy.READ_WRITE)
public class PlayerEntity implements Serializable{
private String nickName;
private long id;
// Getters and setters...
}
------------------------------------

hibernate.cfg.xml:
------------------------------------
<property name="show_sql">false</property>
<property name="hibernate.dialect">org.hibernate.dialect.OracleDialect</property>
<property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="hibernate.connection.username">scott</property>
<property name="hibernate.connection.url">jdbc:oracle:thin:@localhost:1521:HIBER</property>
<property name="hibernate.connection.password">tiger</property>
<property name="hibernate.connection.schema">SCOTT</property>
<property name="hibernate.connection.autocommit">false</property>

<property name="hibernate.cache.use_query_cache">true</property>
<property name="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</property>
<property name="hibernate.cache.use_second_level_cache">true</property>

<mapping class="emil.poker.entities.PlayerEntity"/>
</session-factory>
</hibernate-configuration>
------------------------------------

When I run the main method this is what is displayed:

Get players : 78 ms.
Get players : 31 ms.
Get players : 0 ms.
Get players : 16 ms.
Get players : 0 ms.

But if I remove the @Cache from PlayerEntity and remove the three lines
about cache from hibernate.cfg.xml, this is my result:

Get players : 63 ms.
Get players : 31 ms.
Get players : 0 ms.
Get players : 0 ms.
Get players : 16 ms.

It doesn't seem like the cache is working properly.
Does anyone have any ideas?

According to the log I am missing some configurations files:

WARN - Could not find configuration [org.hibernate.cache.UpdateTimestampsCache]; using defaults.

WARN - Could not find configuration [org.hibernate.cache.StandardQueryCache]; using defaults.

Could this be the reason?


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 11, 2006 5:31 am 
Beginner
Beginner

Joined: Tue Nov 22, 2005 5:33 am
Posts: 31
Forgot ehcache.xml:

<ehcache>
<diskStore path="java.io.tmpdir"/>

<defaultCache
maxElementsInMemory="10000"
eternal="false"
timeToIdleSeconds="120"
timeToLiveSeconds="120"
overflowToDisk="true"
diskPersistent="false"
diskExpiryThreadIntervalSeconds="120"
/>

<cache name="emil.poker.entities.PlayerEntity"
maxElementsInMemory="1000"
eternal="true"
overflowToDisk="false"
/>
</ehcache>


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