wood burning stoves
The moose likes Object Relational Mapping and the fly likes Hibernate: Simpler query with many subclasses Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Hibernate: Simpler query with many subclasses" Watch "Hibernate: Simpler query with many subclasses" New topic

Hibernate: Simpler query with many subclasses

Wirianto Djunaidi
Ranch Hand

Joined: Mar 20, 2001
Posts: 210

We have object relationship that basically a common entity as the parent with many child classes which specialize with different attribute.
We map those relationship using joined-subclass so parent and each children have their own table.
And there are cases where we would like to query just information that is
available in parent table only. How can we do that? Currently hibernate will
automatically do a join on all the children tables on the query. We are concern on the performance and any limit any database has for the SQL length.

Currently we have close to 40 child tables.

[ September 02, 2004: Message edited by: Wirianto Djunaidi ]
Alexandru Popescu
Ranch Hand

Joined: Jul 12, 2004
Posts: 995
Have you tried to define as the proxy of child class the parent class?


blog - InfoQ.com
Gavin King
Ranch Hand

Joined: Aug 31, 2004
Posts: 76
Basically, there is no really efficient way to handle very deep table-per-subclass mappings in ORM. So we say try to avoid such deep inheritance hierarchies.

However, in Hibernate3, you can use a trick:


to handle your case (perhaps) more efficiently. There are tradeoffs between this approach and the <joined-subclass> approach. Usually <joined-subclass> is better, since it is less vulnerable to N+1 selects problems.

Co-Author of <a href="http://www.amazon.com/exec/obidos/ASIN/193239415X/ref=jranch-20" target="_blank" rel="nofollow">Hibernate in Action</a>
I agree. Here's the link: http://aspose.com/file-tools
subject: Hibernate: Simpler query with many subclasses
It's not a secret anymore!