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.  [ 1 post ] 
Author Message
 Post subject: Loading base-class of a joined-subclass hierarchy - solution
PostPosted: Fri Aug 22, 2008 8:55 pm 
Newbie

Joined: Thu Jun 29, 2006 4:46 pm
Posts: 2
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:3.2.6.ga

Name and version of the database you are using:Oracle 10g

I have a class hierarchy with a base class and some 17 derived classes, all extending from a single base. We have such a table structure in the DB already, so mapping it back to the classes. The parent and child tables share the same PK - so this makes it a perfect candidate for joined-subclass mapping.

For the most part, the parent class should be treated as abstract, as records are never inserted only into the parent table. But, queries on the parent table should be supported, and they don't have to be polymorphic - meaning, I don't want the child class instance to be loaded when I query a row on the parent table.

I couldn't find a way to turn off this polymorphic behaviour. I have tried:

    setting polymorphism="implicit"
    defined a custom loader

For the moment, this is how I can working around this problem:
    1. Moved all the fields (except the id) of the base-class into a component.
    2. Redefined the getter and setter methods on the base to delegate the calls to the component.
    3. Added a constructor to the base-class to initialize itself from an instance of this component -- copy constructor (?)
    4. Mapping the component as a separate class by itself
    5. The retrieve() method of the DAO checks if you are trying to query on the base class, in which case, it will query the component instead, and make an instance of the base-class from the component - the copy-constructor above.

From the outside, it looks like you are querying the base-class directly, but you are querying on the component. This way I am able to prevent Hibernate from doing that mammoth outer join on 18 tables!

Please share your views on how you are dealing with this problem, or is there a way to fix this in the mapping/config files itself.

kartheek


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.