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