-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Hibernate Caching with JPA 3.0 annotations
PostPosted: Fri Feb 23, 2007 5:41 am 
Newbie

Joined: Fri Feb 23, 2007 4:38 am
Posts: 2
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().


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.