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 ;)