-->
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.  [ 9 posts ] 
Author Message
 Post subject: second level cache and object disassembly
PostPosted: Wed Aug 10, 2005 2:49 am 
Newbie

Joined: Thu Aug 04, 2005 6:14 pm
Posts: 16
Hi,

I am using Hibernate 3.0 with DB2/iSeries. I have a lot of reference data which does not change at all. Due to the bad db design it is not possible to get all information using SQL. Some data have to be calculated by calling RPG programs which do the magic for you :-( (unless you want to rewrite the RPG programs in Java).

In both cases my problem would be the same:
These attributes are obviously not specified in the mapping file. The values are received in the constructor or when first accessed.

When the objects gets disassembled for second-level cache only attributes specified in the mapping file get cached. This forces me to call the RPG programs every single time the value is needed which really slows down the app.

Is there an elegant way for dealing with this problem. I don't want to create caches for these data manually coz doing so seems kinda odd to me. I know that Toplink caches the whole object (and yes I'm aware of the drawbacks of Toplink) and I'm wondering whether there is a way to tell hibernate to behave similar in this case --> cache the whole object or at least my additional attributes.

Amyway... if there is no other way than doing it manually please let me know.

Thanks for any answers in advance.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 10, 2005 3:56 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
map the properties and use a UserType that does the right thing.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 10, 2005 3:58 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
p.s. it is not silly for you to cache data that hibernate has no way of knowing how to cache

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 10, 2005 7:44 am 
Newbie

Joined: Thu Aug 04, 2005 6:14 pm
Posts: 16
Max, thanks for the reply.

I thought whenever I specify a property in the mapping file it is linked to a column (either with the same name as the property or as specified in the column attribute). Seems like I'm missing something here... I gonna give it a try tonight though...

Although this solution might work I still think it's too much code one has to write. This would mean that I would have to write/use a custom UserType for every String not coming from the DB but set using some other methods during runtime. Is that really considered as 'best practice'???

Thanks alot!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 10, 2005 7:47 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
I have a hard time seeing the problem with this.

Having a UserType gives you separation of concerns, reusability and maintainability compared to having some weird code in the constructor of your domain objects.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 10, 2005 6:55 pm 
Newbie

Joined: Thu Aug 04, 2005 6:14 pm
Posts: 16
OK, tried the UserType approach and managed to map and cache the property. I still have a couple of questions though. As I mentioned earlier the property value is received using a RPG program call and therefore is NOT related to any table / column.

To be able to map the property anyway I used the following line in my mapping file:

Code:
<class name="Consultant" table="csstrlp" mutable="false">
...
<property name="salesData" type="SalesDataType" column="sdlanr" update="false" insert="false"/>
...
</class>


The column is an existing column which is used to receive another value. I just set insert and update to false to be able to reuse this column. Although this works it still looks like a little hack to me... Is there another way on doing this or is this the right and only one?

Also (and even more important) I'm wondering whether it is possible to define a 'per property cache'. Most properties of the Consultant class hardly ever change and therefore can be cached for a long time without the need for refreshing. SalesData, however, is different. It changes quite often and I would like to use a different cache strategy than for the Consultant entities (e.g refresh it every 15min instead of once a day).

I hope I could make my problem clear and would be really grateful if you could help me with this last question. Once again... thanks alot for you help :) !


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 11, 2005 1:53 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
your little hack is all ok. you might even be able to just use a formula - but havent tested it to know if it has some issues (I dont think so)

individual caching settings for properties are not possible.

but you could easily just use whatever cachelibrary you use with hibernate from inside your usertypes.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 11, 2005 6:48 am 
Newbie

Joined: Thu Aug 04, 2005 6:14 pm
Posts: 16
OK, last things I gotta try then is using a formula and setting the property to be lazily fetched. Otherwise I just go with the fake column approach (still don't like it though...)

As far as the caching is concerned I think I just implement the ParameterizedType interface in my UserType as well and pass a parameter specifying the maximum life time for this property.

When I receive the object from cache (that's in the assemble method, isn't it?!) I should be able to check against this property and refresh the object if needed... (at least in theory ;) ). Can't wait till tonight to give it a try...

Alright buddy, thanks a lot for helping me out with this. Really made a couple of things clearer to me. (and maybe one day I will even appreciate this UserType handling ;) )


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 15, 2005 6:54 pm 
Newbie

Joined: Thu Aug 04, 2005 6:14 pm
Posts: 16
Alright after working with this hack for a while now I really don't think this is the way it should be done... It's just dirty!

That's why I started a new, clean thread to clarify this problem from the beginning without leading somebody this - to my opinion wrong - way.

Hopefully all of you experiencing the same problem will find an answer here:

http://forum.hibernate.org/viewtopic.php?t=947682


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