-->
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.  [ 10 posts ] 
Author Message
 Post subject: second level cache and non JDBC data
PostPosted: Thu Sep 15, 2005 6:45 pm 
Newbie

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

I'm facing the problem of having some non persistent attributes which are caculated at runtime. These attributes obviously do not get cached in second level cache (which is essentially just the JDBC data).

This behaviour forces me to recalculate the values over and over again, which is everything but satisfying (especially since some of the calculations are REALLY expensive).

I also tried a little workaround using a custom UserType. Although I ended up with my attribute being cached there is some SERIOUS problem I'm having with this approach:

    1. I really don't think that any of my non persistent attributes should be specified in the mapping file!

    2. Beeing an attribute of the mapping file it needs to be mappend to a column . Also you could use any column in insert=false, update=false mode or formula this is more than a 'little hack' to me... it's just dirty style!

    3. The idea of having a seperate class / user type for every transient attribute just to be able to cache... I don't think I have to say anything more on this. Also all these methods like nullSafeGet(..), sqlTypes(), ... stuff I just don't need here

As far as I know HbmBinder is used to parse the mapping file and analyize which attributes are beeing cached, what is the pk and so on. Is there any way to enhance this (or any other) class to also consider the transient properties of my domain objects (or cache the whole object like TopLink does)?

This problem seems to be sooo straight forward to me that I'm almost sure that I'm missing something here. It can't be that tricky, can it?! #
And if there is really no other way I'm sure some of you guys (if not all) are in the same situation of not wanting to throw away already initialized data...PLEASE letme know what the heck you are doing to get around this issue in a nice and clean way.

This has really been giving me the biggest headaches for the last weeks!

Looking forward to your answers... :-)


Top
 Profile  
 
 Post subject: Re: second level cache and non JDBC data
PostPosted: Thu Sep 15, 2005 6:55 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
tylor wrote:
1. I really don't think that any of my non persistent attributes should be specified in the mapping file!


Why on earth not? The mapping file is for mapping to the cache, as well as to the database.

tylor wrote:
Beeing an attribute of the mapping file it needs to be mappend to a column . Also you could use any column in insert=false, update=false mode or formula this is more than a 'little hack' to me... it's just dirty style!



This is not true. Hibernate properties do not need to be mapped to a column.


tylor wrote:
The idea of having a seperate class / user type for every transient attribute just to be able to cache...


I don't see a priori why you would need more than one UserType to handle all cached attributes. At least all immutable attributes can be handled by one type i guess.


tylor wrote:
I don't think I have to say anything more on this. Also all these methods like nullSafeGet(..), sqlTypes(), ... stuff I just don't need here


Ok, thats just silly.


Hibernate will never implement a shared object cache.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 15, 2005 7:11 pm 
Newbie

Joined: Thu Aug 04, 2005 6:14 pm
Posts: 16
That's what I call a quick answer :-) ...

Quote:
This is not true. Hibernate properties do not need to be mapped to a column.

Not true? When I tried without a column name hibernate tried looking up a database column with the same name as the property which of course resulted in an exception. What am I missing here?

Assuming the above metioned works...this would lead to all my transient properties being initalized when the object is loaded, wouldn't it? (Unless I don't wan't to configure lazy property fetching for these attributes)

Can I modify the attributes from everywhere in my code at any time, even if the jdbc part is immutable, or does the initalization has to happen in the UserType and cannot be touched later on?

Thanks a lot!


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 16, 2005 4:35 am 
Newbie

Joined: Thu Aug 04, 2005 6:14 pm
Posts: 16
ok... been trying to figure out how I can map property without specifying a column for the whole night.

What I'm ending up with is always the same exception:

Code:
Error: Unknown column 'person0_.test' in 'field list'


'test' is obviously the name of my transient attribute which is also used as column name by default.

The exception makes sence to me, considering the following statement from the hibernate documentaion in section 6.1.9. :

Quote:
The <property> element declares a persistent, JavaBean style property of the class.

and also

Quote:
(2) column (optional - defaults to the property name): the name of the mapped database table column. This may also be specified by nested <column> element(s).

So how can I specify properties not related to any columns then? How would the entry in the mapping file look like???
Please help... :-(


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 16, 2005 7:50 am 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
It must be better to calcultate stuff using queries, move calculations from entity to some "business method" or DAO (entity can go as parameter) and use query cache. I think it is a good way, it can help to avoid dependencies on infrastructure to reuse domain data structures (entities) or to decorate calculations. I always use course grained model myself for many reasons.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 16, 2005 6:03 pm 
Newbie

Joined: Thu Aug 04, 2005 6:14 pm
Posts: 16
Guys... you are fully confusing me....

Quote:
- mapping properties not related to any column?
- using the query cache to cache my transient properties? How is that gonna work? I thought it's just used to cache queries which are run quite frequently with the same parameters?

Could you please explain this? I'm really interested in what Gavin mentioned: using the mapping file as mapping to the cache using only a single UserType for all transient properties.

If possible I do not want to map all my non persistent properties like this:

Code:
<property name="salesData" column="sdland" update="false" insert="false" type="test.SalesDataType"/>

Well...in the end this does what I wanted -> cache the transient attribute 'salesData'. But this is really everything but elegant and can't be the recommended way on doing it, don't you think?

Things I don't like here (besides the fact that I have to specify ALL attributes in the mapping file again) that I have to specify a column (in this case I used an already existing one and mapped in read-only)

Also I want to be able to modify the value at any time I wish (so not read only) and update the second level cache with the new values. I don't know whether this is possible with these settings...

If you could please clarify (preferably with a short code snippet) I would be really grateful.

Thanks a lot!


Top
 Profile  
 
 Post subject: Re: second level cache and non JDBC data
PostPosted: Mon Jan 23, 2006 7:04 pm 
Newbie

Joined: Thu Aug 04, 2005 6:14 pm
Posts: 16
tylor wrote:
Beeing an attribute of the mapping file it needs to be mappend to a column . Also you could use any column in insert=false, update=false mode or formula this is more than a 'little hack' to me... it's just dirty style!

gavin wrote:
This is not true. Hibernate properties do not need to be mapped to a column.


hey... it's been a while now and I solved this problem by 'refactoring' my object model and take care of the caching for transient objects myself..

Anyway... I'm still REALLY curious what gavin was talking about in his answer quoted above. How could I map a property without mapping to a column?

If sombody could please clarify this... a simple 'No.. not possible' would be enough. If it is possible, however, please point me to a resource where I can find some more information on that.

Thanks a lot!
TJ


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 21, 2006 6:38 am 
Newbie

Joined: Thu Sep 21, 2006 3:42 am
Posts: 3
Hello tylor,

I am interested in the same.
Can you explain how you have resolved the issue?
Can put examples please?

Thank you very much,


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 21, 2006 11:23 am 
Senior
Senior

Joined: Sat Nov 27, 2004 4:13 am
Posts: 137
what a crazy feature you are talking about!!

why should hibernate have such a feature! is it realted to ORM!?! of course not!

why don't you cache your calculation data yourself?! there are plenty of cache products, so just use them and refactor your DAOs to cache calculated data.

_________________
don't forget to credit!

Amir Pashazadeh
Payeshgaran MT
پايشگران مديريت طرح
http://www.payeshgaran.co
http://www.payeshgaran.org
http://www.payeshgaran.net


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 21, 2006 12:39 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
hibernate handles this just fine.

it's called UserType and/or formula.

_________________
Max
Don't forget to rate


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