I'm trying to use JBossCache as a JPA/Hibernate 2nd level cache provider to cache repeatedly called queries. The queries return entities of a specific type, lets call it FooType.
FooType looks like the following:
@Entity(name = FooType)
@Cache(usage = CacheConcurrencyStrategy.TRANSACTIONAL)
public class FooType {
protected BarType barType;
@ManyToOne(targetEntity = BarType.class, cascade = { CascadeType.ALL })
BarType getBarType() {
return barType;
}
}
So, Footype has a many-to-one association. Now, when I call the query, only a very small part seems to be put in the cache. I think the reason is because I didn't mark the association with the @Cache tag. Am I correct?
But the real question is:
BarType also has a handful of associations, and these return objects which also provide associations and so on, building a big graph of associations. Now, do I need to
a) annotate all of those classes and b) also annotate the associations
in order for the whole query to be cached?