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: Ehcache strategy for mother/daughter classes?
PostPosted: Fri May 09, 2008 10:37 am 
Newbie

Joined: Mon Aug 14, 2006 8:06 pm
Posts: 18
Location: Montréal, Québec
Hibernate version: Hibernate-Annotations 3.3.0
ehcache version: 1.3.0

I am trying to determine what would be a good caching strategy (if any available) for the following setup.

I have a FullPerson persistent class that extends a SimplePerson persistent class.

By and large, the SimplePerson gets (almost) all its data from one row in the main table, while the FullPerson also contains a number of collections which require access to other tables.

It may happen that I first load the SimplePerson and then need to access the corresponding FullPerson. The converse is also possible: I fully loaded FullPerson and soon after the system will want to play with the corresponding SimplePerson.

What would be a good strategy to minimize the database hits? Are Hibernate or its caches "clever" enough to figure out that I am playing with basically the same persistent object? How could I convey that programmatically?


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 09, 2008 2:00 pm 
Newbie

Joined: Mon Aug 14, 2006 8:06 pm
Posts: 18
Location: Montréal, Québec
In case this might incite people to give opinions/ideas/advice, here's my rough line of thought.

1) One of the approaches would be to keep the two objects separate, the Full one extending the Simple one, as highlighted in the previous post. In the cases where I already had at hand a SimplePerson, I could make use of a constructor to go to the FullPerson:
Code:
public FullPerson (SimplePerson simplePerson) {}
which could prefill the FullPerson fields.

Conversely, I could have a projector method on the FullPerson class that would yield the SimplePerson contained within:
Code:
public SimplePerson getSimplePerson() {}
(This is roughly the equivalent of a cast...)

Now that's all very well, but since my application is a Web project, it's in essence amnesic: each action doesn't really remember what's happened before, short of building some sort of in-house cache structure... Hence the hope that Ehcache can cleverly do all the work for me...


2) Another approach would be to do without the SimplePerson object. All the information is packed inside the FullPerson, but thanks to Hibernate's lazy loading strategy, I would then try to tweak the settings so that, by default, when accessing a FullPerson from the database, only the so-to-speak SimplePerson is loaded, and no more work is done by the database than if I had loaded a SimplePerson...

I could then have a (service?) method that ensures that the FullPerson is thoroughly loaded when needed.


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.