-->
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.  [ 2 posts ] 
Author Message
 Post subject: @Transient and 2nd level cache
PostPosted: Sat Mar 24, 2007 6:21 pm 
Newbie

Joined: Tue May 10, 2005 1:19 pm
Posts: 10
Hello all

I have an persistent object type FooBar, with properties foo and bar.
foo is stored in the database, but bar is calculated on demand:

Code:
   @Transient
    public Object getBar() {
      if(bar == null) {
          bar = expensiveCalculation( getFoo() );
      }
      return bar;
    }


Objects of type FooBar are stored in a second level cache. However, the
'master copy' in the cache has bar == null, so the expensiveCalculation
is happening more often than I would like.

Is there any way to modify @Transient to tell the framework to invoke
the getter after the Object is loaded and its fields populated, but
before it is used (to populate the cache or for anything else)? Ideally
I'd like it to be cache aware i.e. called only if the 2nd level cache is
on. That way copy in the cache would have the calculated value and
(hopefully) so would all the instances cloned from it.

I can't use cache callbacks without coupling the app to a particular
cache implementation and even then my preferred implementation does not
define the behaviour if the 'onPut' callback handler modifies the
object.

I can't use hibernate's onLoad event as it's called before the Object's
fields are populated and the calculation requires them. I thought of
calling getBar from the setFoo method, but that causes problems if foo
is a lazy-loaded collection.

Anyone got any other suggestions?

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 26, 2007 3:59 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
try a custom user type

_________________
Emmanuel


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.