I'm using tomcat+hibernate+ehcache
I haven't been able to find a definitive answer as to whether named queries will pull from the L2 cache if the where clause does not use the id of the class. In the following class, my system always goes to the DB for "Group.getByHandle". (all the annotations are JPA except the @Cache)
Is there a way to make this happen?
Code:
@Entity
@Cache(usage=CacheConcurrencyStrategy.READ_WRITE)
@Table(name = "ss_group")
@NamedQueries({
@NamedQuery(name = "Group.getById", query = "SELECT g FROM Group g WHERE g.id=?1"),
@NamedQuery(name = "Group.getByHandle", query = "SELECT g FROM Group g WHERE g.handle=?1"),
})
public class Group implements Serializable {
@Id
@Column(nullable = false, updatable = false)
protected String id = UUID.randomUUID().toString();
// unique name of group
protected String handle = null;
}