-->
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.  [ 3 posts ] 
Author Message
 Post subject: Discriminator for <joined-subclass> would be nice
PostPosted: Sun Dec 07, 2003 6:38 pm 
Regular
Regular

Joined: Tue Dec 02, 2003 6:25 pm
Posts: 61
Location: Dallas, TX
Is there a good way of improving performance for a large number of joined-subclasses?

Our model is something like the following:

Code:
PropertyReport
Appraisal extends PropertyReport
Inspection extends PropertyReport

... about 10 more classes extend PropertyReport

Each PropertyReport subclass has different attributes and is stored in a separate table (appraisal, inspection), with the parent class's attributes stored in a property_report table.

Then I've got several classes with relationships to PropertyReport, for example:

    PropertyReportOrder has a one-to-one relationship with PropertyReport.
    RealEstateProperty has a one-to-many relationship with PropertyReport.
So I can map everything using joined-subclass and it works fine. However, I'm concerned about performance. If I were hand-coding my JDBC I'd have my DAO only join to the appropriate table, based on the property_report_type column.

I can't see any way to do this in Hibernate. It seems like a discriminator on joined-subclass would be just the thing. But apparently discriminator is really only used to discriminate which subclass to load from the same table, rather than determine which subclass to load from one of the other tables.

So I looked into the <any> mapping, but it doesn't look like it will get me all the way there.

I could use an <any> relationship for the relationship between PropertyReportOrder and PropertyReport. However, if I want to use
Code:
session.load(PropertyReport.class, new Integer(1))


It looks like Hibernate would be doing a lot of unnecessary joins.

Has anyone else encountered this issue?

Again, it seems like the ideal thing would be a <joined-subclass> for which I could define a discriminator-value. But it doesn't seem to work.

This is a new loan management system, so we can adjust the database and the model as we see fit, although I'd (naturally) like to keep it as simple and straightforward as possible. If anyone has any suggestions I'd love to hear them

I've thought about trying to write a custom persister (extending NormalizedEntityPersister?), but I really have no idea how much effort that would take.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 08, 2003 1:21 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
OK, suppose I run a query that returns 30 instances of PropertyReport.

Why do you believe that it would be faster to run this query as 30 + 1 seperate requests to the database, instead of just one request that joins across 10 tables?

Have you actually *tested* this? Have you considered the impact upon system latency when the database is in a seperate physical tier?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 08, 2003 4:25 am 
Regular
Regular

Joined: Tue Dec 02, 2003 6:25 pm
Posts: 61
Location: Dallas, TX
gavin wrote:
OK, suppose I run a query that returns 30 instances of PropertyReport.

Why do you believe that it would be faster to run this query as 30 + 1 seperate requests to the database, instead of just one request that joins across 10 tables?


Good point. I have no foundation for such a belief, and I'm not equipped with any sort of benchmarks on the latency tradeoffs between joins and requests across tiers.

It was just a hunch. I've spoken with a few people who have had similar problems while hand-coding database access, and all had chosen to use a two-step process to limit joins, rather than a one step process that performs all joins.

I was imagining that there would be less than 30 requests -- that the persister could execute one request per persistent subclass discovered by the first query. So at most there would be 10 + 1 requests, at the least 1 + 1. Probably a crazy notion -- hadn't really thought through it.

So is that how the <any-to-many> mapping works? Would it execute 30 + 1 queries for such an association?

gavin wrote:
Have you actually *tested* this?


Things work very well at the moment, although we haven't done any performance testing.

gavin wrote:
Have you considered the impact upon system latency when the database is in a seperate physical tier?


Yes, but as I said I don't pretend to know the tradeoffs. If you can recommend any good crash courses in that sort of thing, I'd be eager to read up on it.

Mainly, I just wanted to get some feedback on whether my current approach using joined-subclass is the best strategy. I feared I might have been misusing joined-subclass.

I definitely like the elegance -- not having to worry about a discriminator. I just hadn't seen anyone do it this way before.

I found this thread and it discusses many of my questions: http://forum.hibernate.org/viewtopic.php?t=925297&highlight=joinedsubclass+discriminator

My most common use case will be calling property.getPropertyReports(), and most of the time I will only need superclass information. I don't imagine we'll be writing any queries that will use subclass attributes.

Also, I've thought about changing from inheritance to association so that I could lazy load. something like:

Code:
class PropertyReport
class Appraisal extends PropertyReport
class AppraisalDetail


with a mapping like:
Code:
<class name="PropertyReport">
   <id column="id" name="id" type="int">
      ...
   </id>
   <discriminator column="property_report_type"></discriminator>
   superclass properties...
   <subclass name="Appraisal" discriminator-value="Appraisal">
      <one-to-one name="detail" class="AppraisalDetail"></one-to-one>
   </subclass>
</class>
<class name="AppraisalDetail" proxy="AppraisalDetail" table="appraisal">
   ...
</class>


How does that look?

I really like the simplicity of the joined-subclass implementation, I just want to be sure that I am not setting myself up for any embarassing performance problems. It just seems too easy ;)


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