File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Object Relational Mapping and the fly likes Mixing inheritance strategies for multi-level inheritance in Hibernate Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Mixing inheritance strategies for multi-level inheritance in Hibernate" Watch "Mixing inheritance strategies for multi-level inheritance in Hibernate" New topic
Author

Mixing inheritance strategies for multi-level inheritance in Hibernate

Marco Tulio Borges
Ranch Hand

Joined: Sep 14, 2004
Posts: 45
Hello, there Ranch folks! I'm facing a problem with multi-level inheritance in Hibernate, mixing inheritance strategies. I have not found any examples or solutions to this particular problem on the web, so let me try to describe it:

This is my class hierarchy:


A (abstract class)
|-B (abstract class)
| |-C
| |-D
|-E


In other words: C and D extend B while E and B extend A. Classes B and A are abstract.

My database is set this way: I have a table named "table_A", a table named "table_B" and a table named "table_E".

I'm using Java 5 with Hibernate 3.2.1 (with Annotations 3.2.0). The mapping looks like this:



The real problem happens when I'm trying to query for a list of entities of type A. Looks like Hibernate is not trying to instantiate C and D by the single table strategy. Hibernate is trying to resolve C and D using the InheritanceType.JOINED strategy, looking for tables with names "C" and "D", since the name of the table is not specified. Apparently Hibernate is ignoring the second strategy (InheritanceType.SINGLE_TABLE). I read somewhere (hard to find out where, after so many searches) that Hibernate can handle mixing strategies in this multi-level inheritance problem. What am I doing wrong?
[ January 11, 2008: Message edited by: Marco Tulio Borges ]

.: SCJP 1.4 (95%) / SCWCD 1.4 (91%) / SCBCD (77%) :.
"Sometimes I think the surest sign that intelligent life exists elsewhere in the universe is that none of it has tried to contact us." - Calvin
Vijay Kalakoti
Greenhorn

Joined: Nov 08, 2004
Posts: 2
Check this link: http://opensource.atlassian.com/projects/hibernate/browse/HHH-1175

It seems like it's possible atleast with xml mapping. Not sure about annotations though...


Any problem in Computer Science can be solved by adding a level of indirection -- Ion Stoica
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Mixing inheritance strategies for multi-level inheritance in Hibernate