Using EhCache for session.createCriteria(...).list()
Posted
by James Smith
on Stack Overflow
See other posts from Stack Overflow
or by James Smith
Published on 2010-06-12T16:06:30Z
Indexed on
2010/06/12
16:13 UTC
Read the original article
Hit count: 247
I'm benchmarking the performance gains from using a 2nd level cache in Hibernate (enabling EhCache), but it doesn't seem to improve performance. In fact, the time to perform the query slightly increases.
The query is:
session.createCriteria(MyEntity.class).list();
The entity is:
@Entity
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class MyEntity {
@Id
@GeneratedValue
private long id;
@Column(length=5000)
private String data;
//---SNIP getters and setters---
}
My hibernate.cfg.xml is:
<!-- all the normal stuff to get it to connect & map the entities plus:-->
<property name="hibernate.cache.region.factory_class">
net.sf.ehcache.hibernate.EhCacheRegionFactory
</property>
The MyEntity table contains about 2000 rows.
The problem is that before adding in the cache, the query above to list all entities took an average of 65 ms. After the cache, they take an average of 74 ms. Is there something I'm missing? Is there something extra that needs to be done that will increase performance?
© Stack Overflow or respective owner