Hi,
Are the following examples the only ways to hit the second-level cache?
1.
Code:
User user = (User) session.get(User.class, new Long(1));
2.
Code:
Iterator users = session.createQuery("from User u where u.firstName = :firstName").setLong("firstName", firstName).iterate();
Why doesn't the following code example hit my second-level cache (ehcache 1.3.0)?
Code:
User user = (User) session.createCriteria(User.class).add(Restrictions.idEq(new Long(1))).uniqueResult();
The Criteria API should have all the information it needs to query the second-level cache, i.e. the identifier and the User class.
Hibernate version: 3.2.5ga
Mapping documents:
<class name="xxx.User" table="user" lazy="true">
<cache usage="nonstrict-read-write" />
<comment>Hibernate Mapping for User</comment>
<id name="id" column="id">
<generator class="native" />
</id>
<property name="alias" column="alias" />
<property name="createdTime" column="created_time" type="timestamp" />
<property name="email" column="email" />
</class>
Name and version of the database you are using: MySQL 5.0.42 (Linux CentOS)