-->
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: Possible to change the inheritance mapping in a hierarchy?
PostPosted: Mon Jan 09, 2006 3:25 pm 
Beginner
Beginner

Joined: Mon Jan 09, 2006 3:05 pm
Posts: 24
With Hibernate Annotations (3.1B7), is it possible to change the inheritance mapping strategy within a class hierarchy?

For example, I have an class hierarchy, with an abstract superclass and two concrete subclasses. One of the subclasses has no additional properties, while the other has some additional data. I'd like the simple subclass to be mapped onto the superclass table using the SINGLE_TABLE inheritance mapping, and the subclass with the additional info to be mapped using the JOINED strategy. If they both use JOINED, I get a table for the simple subclass without any columns except for the primary key.

I know JSR-220 Proposed Final Draft says "Support for the combination of inheritance strategies within a single entity inheritance hierarchy is not required by this specification", but can set up the desired mapping in traditional Hibernate by mixing table per class hierarchy with table per subclass inheritance mappings to avoid the undesired table.

Given the support in the underlying Hibernate, is this something I can expect Annotations to support, or am I missing something and it already works? Pointers to examples would be great.
--keenan


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 12, 2006 2:57 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
not yet

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 20, 2006 3:24 pm 
Beginner
Beginner

Joined: Mon Jan 09, 2006 3:05 pm
Posts: 24
The new Annotations 3.1B8 now explicitly warns "Mixing inheritance strategy in a entity hierarchy is not allowed, ignoring sub strategy".

However, I found a way of accomplishing the database mapping I desired in Gavin's Hibernate presentation at JavaOne 2005. The presentation can be found at http://developers.sun.com/learning/javaoneonline/2005/coreenterprise/TS-3628.pdf, and in particular pages 18 and 19, Mixing Strategies, gave me the pattern.

Map the superclass with Single Table, so the subclass without additional properties is mapped into it without the extraneous table that the Joined stragegy would have generated. Then for the subclass with additional data, specify a @SecondaryTable and use that table for all the properties specific to that subclass.

It would be nice if we could mix inheritance strategies within a hierarchy, as is possible with core hibernate, to avoid this subterfuge. But for now it works well.
--keenan


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 20, 2006 6:08 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
This is planned (at least in my mind), but not everything is doable, it's not as simple as it looks like.

_________________
Emmanuel


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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.