-->
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.  [ 4 posts ] 
Author Message
 Post subject: Getting CacheKey for an object
PostPosted: Wed Jan 20, 2010 9:29 pm 
Newbie

Joined: Mon Apr 14, 2008 1:13 pm
Posts: 11
So I'm using Hibernate with ehcache as a 2nd level cache provider.

In some cases I manually create a Hibernate entity (that is, I'm not loading it from the DB) and then wish to put this entity in the appropriate ehcache cache instance.

And I know ehcache caches based on the org.hibernate.cache.CacheKey of a Hibernate entity.

My question is how do I get the CacheKey of a given object I instantiated myself to use for the cache put?

I see the constructor API doc but am looking for a code example since I'm not sure exactly what I need to pass or if that's even the right way to go about getting a CacheKey.


Top
 Profile  
 
 Post subject: Re: Getting CacheKey for an object
PostPosted: Thu Jan 21, 2010 3:52 am 
Expert
Expert

Joined: Tue Jun 16, 2009 3:36 am
Posts: 990
Hi,

also I am using EHcache as 2nd level cache provider,
but I see absolutely no reason why someone should manually put instances into 2Lcache!
Hibernate does it automatically for you if you define your persistent classes properly.


Top
 Profile  
 
 Post subject: Re: Getting CacheKey for an object
PostPosted: Wed Jan 27, 2010 12:45 pm 
Newbie

Joined: Mon Apr 14, 2008 1:13 pm
Posts: 11
To be clear, I'm just JPA w/ Hibernate impl.

When I do entityManager.find(Foo.class, 1) the entity IS cached and REPLICATED.

But the issue I'm seeing is that entityManager.persist does not cache the newly created object.

I could do persist then find I guess but I'd prefer to just do the cache put myself.

But perhaps I'm missing something and persist should in fact cache the new entity?


Top
 Profile  
 
 Post subject: Re: Getting CacheKey for an object
PostPosted: Wed Jan 27, 2010 2:04 pm 
Newbie

Joined: Mon Apr 14, 2008 1:13 pm
Posts: 11
I guess the answer is NOT to use persist... entities passed to persist are NOT cached or replicated :-)

If you call merge in all cases, it will replicate the change. Good enough for me I guess!


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

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.