-->
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.  [ 4 posts ] 
Author Message
 Post subject: Where Clause for joined-subclass
PostPosted: Sat Dec 10, 2005 6:38 pm 
Beginner
Beginner

Joined: Sat Dec 10, 2005 6:22 pm
Posts: 28
Location: Chicago, IL
I have class hierarchy like the following.
Fruit
--Apple
----Red Delicious Apple
----Granny Smith
--Orange
--Strawberry

...etc

The db is structured as follows:
t_fruit
FruitKey int
FruitType int
FruitName varchar(255)

t_apple
FruitKey int
FruitType int

t_apple_grannysmith
FruitKey int
FruitType int

t_orange
FruitKey int
FruitType int

I would like to either modify NHibernate to use a discriminator with a joined-subclass or take a where clause as the parameter of the joined-subclass. Because constraints are used on the subclass FruitType columns a where clause would allow the db to execute much quicker by eliminating the multiple joins created in the select statements.

I am brand new to NHibernate, I am trying migrate a roll-your-own DAL into NHibernate and would love to see this type of feature supported.

Any thoughts from experts on where to start or if this is even possible?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 12, 2005 4:57 am 
Regular
Regular

Joined: Fri Jun 11, 2004 6:27 am
Posts: 81
Location: Yaroslavl, Russia
According to described table structure you don't need <joined-subclass> at all: all of derived tables you've shown contains only id and type. If it really looks like this, then <subclass> will be enough.

On the other hand, if the given structure is just a sample and there are additional fields in joined tables, then you will anyway need joins to fetch all object's data from the database.

And the last: if you belive that your approach will help queries to run faster, you can check it first by creating database views and mapping your classes to those views instead of tables.

_________________
Best,
Andrew Mayorov // BYTE-force


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 12, 2005 7:47 pm 
Beginner
Beginner

Joined: Sat Dec 10, 2005 6:22 pm
Posts: 28
Location: Chicago, IL
Quote:
According to described table structure you don't need <joined-subclass> at all: all of derived tables you've shown contains only id and type. If it really looks like this, then <subclass> will be enough.

For sake of brevity I withheld all the column props. An Orange needs to be joined to the Fruit table so it can load all the fruit properties or am I missing something?

Quote:
And the last: if you believe that your approach will help queries to run faster, you can check it first by creating database views and mapping your classes to those views instead of tables.

This would be a good exercise I will try and test this to get some real numbers.

Everything in the system is a subclass of Fruit, technically an object called Item, each concrete subclass has a table with the additional properties related to the subclass. The reason every table also has an ItemTypeKey field was to enforce constraints on the items being inserted as well as provide better performance for generic selects. The old DAL was also able to use the ItemTypeKey as a discriminator to know what object to instantiate.

I was looking at Hibernate 3.0 and it seems they have the functionality I require. Looks like I need to wait until NHibernate gets an update.

Is there a roadmap on getting a comparable NHibernate 3.0 release?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 13, 2005 6:00 am 
Regular
Regular

Joined: Fri Jun 11, 2004 6:27 am
Posts: 81
Location: Yaroslavl, Russia
I think i understand you: we also have "object type" field in a base table for joined-subclass hierarchy, and i also would like joined-subclasses to support discriminators. But it would help performance in one case only - then you use base class in a query. In this case NH must join all the subtables in one select (usin left joins) and then select object class according to empty parts of the resultset. If you specify "leaf" class in a query, it works quite optimal already.

You see, it's not a matter of where clause, it's more complex question - how could you load instances of several possible types in one select w/o joining their tables alltogether?

_________________
Best,
Andrew Mayorov // BYTE-force


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