I'm using Hibernate + Spring with JPA 3.0 annotations, and using EhCache to cache the hibernate objects.
The cache seems to work fine for a simple objects like AppsLookupDetail object below:
@Cache(usage = CacheConcurrencyStrategy.READ_ONLY)
public class LookupDetail implements Persistable, HasNumericPrimaryKey{
private String type;
private String code;
private String meaning;
}
However i'm not able to make it work for slightly complex object graphs where one hibernate object references another hibernate object which is either eager fetched or lazy fetched.
I've added the same annotation for these referenced objects but somehow they always get synched up with the database changes which means a new query is being fired.I'm confused if i am annotating them properly.
The example is given below:
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class SubscriberDetail implements Persistable, HasNumericPrimaryKey {
private PrincipalDetail principal; // eager loaded hibernate object
private String firstname;
private SubscriberProfileDetail profile; // lazy fetched hibernate object
@OneToOne(cascade = {CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REFRESH}, fetch = FetchType.LAZY)
@JoinColumn(name = "profile_id")
public SubscriberProfileDetail getPersonalProfile() {
return profile;
}
@ManyToOne
public PrincipalDetail getPrincipal() {
return this.principal;
}
}
firstname is always picked from the cache, Principal & Profile object always pick up the database changes.
How can i put the entire object graph into ehcache so that i don't need to requery it ? Is there any annotation missing that needs to be added to getPrincipal() or getPersonalProfile().
|