-->
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.  [ 2 posts ] 
Author Message
 Post subject: Overriding Inheritence strategy?
PostPosted: Wed May 30, 2007 3:41 am 
Newbie

Joined: Tue Jan 23, 2007 5:03 am
Posts: 5
Hello,

I have posted this in ther german forum but there comes no reply -- so i give it here another try . . .

I am working with Hibernate-Annotations and after some smaller problems i got further and further ;-)

But there is a bigger problem i couldnt solve yet. There is a inheritence structure I could not set in annotations yet.
I have got some classes:

Code:
                               ----------
                               |  News  |
                               ----------
                                   ^
                                   |
                                   |
                      ----------------------------
                      |    AbstractAdHocNews     |
                      ----------------------------
                           ^                ^
                           |                |
                           |                |
                      ----------       ----------
                      |  SMS   |       |  Email |
                      ----------       ----------



SMS and Email are extended AbstractAdHocNews which should be mapped within a SINGLE_TABLE called AdHocNews. Furthermore, AbstractAdHocNews and News should be in two different tables. So I marked the inheritence strategy of News with TABLE_PER_CLASS. But there should remain a reference of all AbstractNews in the table News. I tried to use @MappedSuperClass: This created two tables as I want, but all attributes of the superclass News were in the AbstractAdHocNews table as well. I want it like this:

Code:
                     News
                      ----------------------------------
                     |id | news_att1 | news_att2 | ... |
                      ----------------------------------

                     AbstractAdHocNews
                      --------------------------------------------
                     |id | discr | adhoc_att1 | adhoc_att2 | ... |
                      --------------------------------------------


"discr" is the discriminator value, e.g. "sms" or "email".

My result for now is that I have got no AbstractAdHocNews table. I get a SMS table and a Email table. Isnt it possible to override inheritence strategys?

My Mapping Annotation Signatures are as the following

## News ##

@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public class News implements Serializable {
. . .
}

## AbstractAdHocNews ##

@Entity
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name="NEWS_TYPE",discriminatorType=DiscriminatorType.STRING)
public abstract class AbstractAdhocNews extends News {
. . .
}

## SmsNews ##

@Entity
@DiscriminatorValue("SMS_NEWS")
public class SmsNews extends AbstractAdhocNews {
. . .
}

## EmailNews ##

@Entity
@DiscriminatorValue("EMAIL_NEWS")

Thanks for your help

Henning
[/b]


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 01, 2007 12:47 am 
Newbie

Joined: Tue Jan 23, 2007 5:03 am
Posts: 5
Reference says (2.2.4):

@Inheritance and @DiscriminatorColumn should only be defined at the top of the entity hierarchy.

so well, top of the entity . . .

somewhere else (deeper at the end):

(7) inheritance: defines the inheritance strategy (JOINED, TABLE_PER_CLASS, SINGLE_TABLE), Available only at the root entity level

aaaaaaaaaah, the root level of the inheritence!


The next time when I try something out, I´ll search the whole reference for the keyword . . .

I hope this saves some time for others who didn´t get that point, too.

so long

Henning


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.