-->
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: How to cache not mapped instance variable ?
PostPosted: Mon Aug 01, 2005 8:06 pm 
Newbie

Joined: Mon Aug 01, 2005 7:17 pm
Posts: 3
Hibernate version:3.0.5 (with EHCache)
A general question.

Hi everone.

Mapping and (second-level-)caching are working fine, but....

Imagine two small beans with getters and setters, let's say "PersonBean" and "ContractBean".

Attributes of PersonBean:
1. String name
2. Integer age
3. ContractBean contract

Attributes of ContractBean:
1. Integer contractType
2. Boolean isValid
3. Date expiryDate

Let's say "name" and "age" are gathered from a database with hibernate from a database.
The information for the ContractBean is gathered by calling a native program in the getContact-method of the PersonBean.
"Name" and "age" are cached well, but the "contract" isn't, so the native program has to be called every time (it shouldn't ;-)

How to add this one (not mapped) attribute "contract" to the cache ?
Or is there a possibility to do this by modifing the mapping, although this information isn't stored in a database ?


Thanks for any answers in advance


Top
 Profile  
 
 Post subject: Re: How to cache not mapped instance variable ?
PostPosted: Tue Aug 02, 2005 6:27 pm 
Newbie

Joined: Mon Aug 01, 2005 7:17 pm
Posts: 3
PropertyAccessor should do the job, does it ? How to use it ? No documents/examples found...


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 04, 2005 6:34 pm 
Newbie

Joined: Thu Aug 04, 2005 6:14 pm
Posts: 16
I'm facing the same problem rigtht now. My classes are having a couple of properties which are calculated when first accessed in a really expensive way. Unfortunately hibernate does not seem to cache any attributes not specified in the mapping file.

I don't think PropertyAccessor is what you are looking for. Although I don't have that much experience with hibernate but I don't see implementing a property accessor for each non persistent attribute as a solution.

You could try using the CacheManager and create your own cache. Although I don't have any other ideas I don't think is an elegant solution for our problem either :-( ...

Maybe I'm missing something here and there is an easy way to tell hibernate / ehcache to also cache transient attributes...

Good luck


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 08, 2005 6:55 pm 
Newbie

Joined: Mon Aug 01, 2005 7:17 pm
Posts: 3
Hmm, is this issue a weak point of Hibernate at all ?

UserTypes or an own CachingManager cannot be the solution.
Tylor's and my problem seems to be very trivial, but can not be solved with Hibernate ?

Hmm, am I really right ? :-(
Or just too blind to find a proper way ? ;-)


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.