I use ehcache and hibernate 3.6.7 Final. This a pseudo code sample that reveals problem with caching.
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class A{
long id;
@OneToMany(mappedBy = "aId", targetEntity = B.class, fetch = FetchType.LAZY)
@Fetch(value = FetchMode.JOIN)
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
protected Set<B> fieldB;
}
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class B {
long id;
long bId;
}
1) First time when I load entity A from hibernate it does not read fieldB. And this is ok - cause FetchType.LAZY is set.
2) Second time when I load entity A I see sql queries retrieving entity A JOIN entity B.
3)If remove @Fetch(value = FetchMode.JOIN) point 2 will not be performed.
So the question is this bug or feature? And how can I avoid such latent things.