I tried first time to use second level cache according different tutorials and it doesn't work. I have class :
@Entity
@Table(name="TABLE_NAME")
@org.hibernate.annotations.Cache(usage=CacheConcurrencyStrategy.READ_ONLY)
public class Foo {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
@OneToMany(mappedBy = "foo", cascade = CascadeType.ALL, fetch = FetchType.EAGER)
private List<Sentence> collection_name;
and configuration in my hibernate.cfg.xml file
<property name="hibernate.cache.region.factory_class">org.hibernate.cache.ehcache.EhCacheRegionFactory</property>
<property name="hibernate.cache.use_second_level_cache">true</property>
<property name="hibernate.cache.use_query_cache">true</property>
I turned on
<property name="show_sql">true</property>
I thought that second query won't hit database, but it does.
my Query :
List<Foo> result = session.createQuery("select p from Foo p order by size(p.collection_name) desc ").list();
What is wrong ?