I am working on performance improvement in my application. I add second level cache to some objects. I used Junit to see result of second level cache. I see, that when I am using function
Code:
getSession().createCriteria
everything seems to be ok. I can see that time to get next object is lower.
When I am using DetachedCriteria it seems that second level is off.
My config file looks like:
Code:
<prop key="hibernate.current_session_context_class">thread</prop>
<prop key="hibernate.cache.use_query_cache">true</prop>
<prop key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</prop>
<prop key="hibernate.cache.use_second_level_cache">true</prop>
<prop key="hibernate.show_sql" >true</prop>
<prop key="hibernate.generate_statistics">true</prop>
<prop key="hibernate.cache.use_structured_entries">true</prop>
Query:
Code:
public List<ProcessDef> getAllProcessDef() throws Exception {
DetachedCriteria criteria = DetachedCriteria.forClass(ProcessDef.class);
getHibernateTemplate().setCacheQueries(true);
return getHibernateTemplate().findByCriteria(criteria);
}
Mapped object using annotation:
Code:
@Entity
@Table(name = "MNP_PROCESS_DEF", uniqueConstraints = { @UniqueConstraint(columnNames = { "NAME" }) })
@Cache(usage=CacheConcurrencyStrategy.READ_ONLY)
public class ProcessDef {
private Long id;
private String name;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "PROCESS_ID", nullable = false)
public Long getId() {
return id;
}
@Column(name = "NAME", nullable = false, length = 16)
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public void setId(Long id) {
this.id = id;
}
And its corresponding ehcache configuration :
Code:
<cache name="ecrm.core.dao.db.model.process.ProcessDef"
maxElementsInMemory="10"
eternal="true"
overflowToDisk="false"
/>
Any idea why my DeatechedCriteria does not work with secend level?