Hi there,
I'm using ehcache 1.7.0 + jgroups 2.4.2 + hibernate 3.2.4.sp1.cp07 (as part of JBoss 4.3.0 GA EAP CP04) to do a clustered cache and I'm seeing some interesting behavior where there seems to be an optimization happening in the query/2nd level caches that is making the clustering act strangely.
I have two servers, A and B. Each of the operations is happening through Hibernate.
Code:
@NamedQueries({
@NamedQuery(
name="Member.FindByEmail",
query="from Member memb where memb.email = :email",
hints={
@QueryHint(name="org.hibernate.cacheable", value="true")
}
),
@NamedQuery(
name="Member.CountAllMembers",
query="select count(*) from Member",
hints={
@QueryHint(name="org.hibernate.cacheable", value="true")
}
)
})
@Entity
@Cache(usage=CacheConcurrencyStrategy.READ_WRITE)
public class Member implements Comparable<Object>, Serializable
The steps to reproduce:
A1: execute named query: Member.CountAllMembers.
B1: execute named query: Member.CountAllMembers.
A2: Insert a row into the Member table.
B2: Attempt to query for the newly added Member using Member.FindByEmail.
B2 fails to find the member. I can see that no database hit occur from my mysql query log. (Member)q.getSingleResult();... this throws a NoResultsException.
Here is the trick: If I run A1 again, then B2 can immediately find the member.
It seems there is an optimization on B that says that if the count hasn't changed, then only look in the second level cache and don't bother hitting the database even though it is a cache miss.
Thoughts?