-->
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: How to accompish an embedded class hierarchy?
PostPosted: Wed Oct 18, 2006 4:23 am 
Newbie

Joined: Tue Oct 17, 2006 11:58 pm
Posts: 2
Location: Whidbey Island, WA
I have a case where I'd like to use an embedded class (i.e., @Embeddable) but would like to have the value be from a class hierarchy rather than a single class. I tried adding @Inheritance and @DiscriminatorColumn annotations to my @Embeddable class and they were ignored. Reading the EJB 3.0 Persistence Spec carefully I noted that in section 9.1.29 it says that the Inheritance Annotation is used to create "entity" class hierarchies so this is apparently working to spec.

So the question is, am I missing a way to accomplish this or another way to look at the issue? I have also looked at the Hibernate documentation and have not found anything that seemed to apply there either though I have not read them as closely as I have the EJB 3.0 spec.

I am attempting to use an embedded class for two reasons. First, the combination of fields occurs in many records and they form a coherent class. Second, the embedded class hierarchy is not central to the classification of the records and thus I do not wish to move the inheritance into the entities.

My main option at this point seems to be to flatten out the hierarchy to a single class thus cluttering up the interface with all possible methods and to implement any polymorphic behavior using if or switch statements.

I would be happy to add more detail but I'm not sure what direction this will go and thus what would be useful.

Thank you in advance for your thoughts.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 23, 2006 4:03 am 
Newbie

Joined: Wed May 10, 2006 1:05 pm
Posts: 6
I faced the same issue some weeks ago. After playing araound a bit and reading the specs, I came to the conclusion, that it's just not possible to do inheritence on embeddables with Hibernate and/or JPA. In fact, I guess it would be quite hard to support it in a semantically cohereant way. For example, think about an entity embedding more than one Embeddable, each of them being part of an inheritence hierarchy.

Anyway, it would be great to get some enlightenment on the subject from the pros. And it would be fine, if the specs and manuals could explicitly point out the fact, that inheritence on embeddables is not supported.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 25, 2006 10:41 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
The closest thing you can do today is to use @MappedSuperclass on your superclasses.
This is an Hibernate extension though

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 15, 2009 9:26 pm 
Newbie

Joined: Tue Apr 14, 2009 7:44 pm
Posts: 1
I also want to embed a polymorphic reference.

emmanuel wrote:
The closest thing you can do today is to use @MappedSuperclass on your superclasses.
This is an Hibernate extension though


Can someone give details on this? No combination of @MappedSuperclass and @Inheritance annotations on the sub and super classes that I've tried gets hibernate to correctly persist subclasses.

This is essentially the model that I want to map
Code:
public abstract class ChildSuperClass {}

@Entity
public class Parent {
    @Embedded
    private ChildSuperClass child;
}

public class ChildA extends ChildSuperClass {
    private int [] ASpecificField;
}

public class ChildB extends ChildSuperClass {
    private String [] BSpecificField;
}


Thanks.


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