-->
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.  [ 6 posts ] 
Author Message
 Post subject: How to optimize the getObjectById() operation?
PostPosted: Fri May 06, 2005 6:04 am 
Beginner
Beginner

Joined: Thu Feb 26, 2004 6:59 am
Posts: 47
Location: Gurgaon, India
Hi,

We have a scenario where we have a large number of data objects, say 100. Every object is extended from a basic class, say 'BasicObject.java'. There are also some objects which may have multiple level of inheritence hierarchy (but not more than 5).

Now, we are supporting an API that is getObjectById(long id). For getting the objects, we are calling

session.getObjectById(BasicObject.class, id);

i.e. specifying the Basic Object class instead of actual extended class.

To fetch the object of right type, hibernate have to make the outer join on all the extended tables for finding out the exact type of the objects. As we have 100 tables which are extending from the same basic class, won't it be too heavy?

Please help,

- whether we are wrong in understanding the behavior of this operation
- or there is any alternate approach for meeting these kind of requirements.

If we are right, one solution may be to put a 'class name' field in 'basic object' class. So on getting request, first we get the class name for the id from 'basicObject' table and then try getObjectById() with retrieved class name and id. But it also involves two hits to the database. Is it the right approach?

waiting for replies, Thanks
Mohit.


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 06, 2005 6:30 am 
Expert
Expert

Joined: Fri Nov 07, 2003 4:24 am
Posts: 315
Location: Cape Town, South Africa
Quote:
As we have 100 tables which are extending from the same basic class, won't it be too heavy

Yes - this is going to be an extremely expensive operation if you use a table per class/concrete class mapping approach.

Have you considered other inheritance mapping strategies: 'Table per class hierarchy' will minimise the hit on the db but you may have a large number of redundant fields.


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 10, 2005 3:53 am 
Beginner
Beginner

Joined: Thu Feb 26, 2004 6:59 am
Posts: 47
Location: Gurgaon, India
Thanks DRJ

Yes there are some alternative approaches but those have their own drawbacks, as you have suggested. Thats why I am looking for a optimum solution for this problem.

I hope someone on the forum may have faced this problem and can guide us that what is the standard approach for meeting this requirement considering performance and memory issues.

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 11, 2005 11:04 pm 
Beginner
Beginner

Joined: Thu Feb 26, 2004 6:59 am
Posts: 47
Location: Gurgaon, India
We are using joined-class mapping approach.

I am still not getting the solution that how can we optimize such an operations. Do we need to customize the table structure ourselves as I have written in my first post?

Please suggest if there is any standard or testet approach for this requirement.

Thanks,
Mohit


Top
 Profile  
 
 Post subject: Re: How to optimize the getObjectById() operation?
PostPosted: Thu May 12, 2005 2:47 am 
Regular
Regular

Joined: Fri Oct 01, 2004 2:19 am
Posts: 111
Location: Melbourne, Australia
mohitgupta_india wrote:
Hi,
<snip>

If we are right, one solution may be to put a 'class name' field in 'basic object' class. So on getting request, first we get the class name for the id from 'basicObject' table and then try getObjectById() with retrieved class name and id. But it also involves two hits to the database. Is it the right approach?

waiting for replies, Thanks
Mohit.


This will not solve your initial problem, but:
Hibernate supports the notion of an <any> type which allows it to repersent
polymorphic references to instances of types in your domain. You need
to speciffy the pairing of key name/type for identifying an instance of
a particular type and Hibernate will know how to resolve to the right
type, etc. Behaind the scenes, Hibernate represents the reference in a
manner similar to your suggestion - by creating a discriminator field.

Note however, that this does not help in your initial use case since
providing the id to Hibernate is not sufficient when the possible number
of types is large, but it could help when you have references to instances
of your BasicObject in other objects.

_________________
Cheers,

Bonny

please don't forget to rate :)


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 16, 2005 5:51 am 
Beginner
Beginner

Joined: Thu Feb 26, 2004 6:59 am
Posts: 47
Location: Gurgaon, India
Thanks Bonny,

But first case is critical for us. For maintaining the references, we are using our own framework.

Thanks
Mohit.


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