-->
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.  [ 3 posts ] 
Author Message
 Post subject: When use the @entity annotation (in regard to inheritance)?
PostPosted: Wed Jan 14, 2009 8:38 am 
Newbie

Joined: Wed Jan 14, 2009 8:21 am
Posts: 4
Hello everybody.

Ok, the question may seem completely stupid to ask but, after thinking a little about it, I find myself unable to precisely answer to it.

As I understand it, the @Entity annotation has to be added on classes that have to be persisted. But what happens when the classes I want to persist extend other classes or implement interfaces? Does each ancestor have to have the @Entity annotation added as well?

More specifically, if, when mapping Inheritance, I traverse an abstract class that does not have any property, do I still have to annotate it with @Entity or not?

If you know more about the details, could you also explain what technically happens when a class gets Annotated like this?

Thank you very much in advance,

Jérôme


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 14, 2009 8:54 am 
Expert
Expert

Joined: Thu Jan 08, 2009 6:16 am
Posts: 661
Location: Germany
Hi,
No you don't have to add @Entity to every class in the inheritence-tree. It is also not possible. Every class implicitly extends Object, which you can not annotate. ;-)

Only properties in the class, which is annotated as Entity are mapped.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 14, 2009 9:39 am 
Newbie

Joined: Wed Jan 14, 2009 8:21 am
Posts: 4
Meaning that as soon as I have a property that I wish to see appearing in a table, I either have to map it with @Entity annotation (or @MappedSuperclass if I want to have some "templating", as I have just read).

But my question is still pending for abstract classes that do not hold any property.

Let's say that I have:
A (root - defines some properties)
B - C (middle abstract classes - no properties defined)
D (extends B and defines some properties)
E - F (idem as just above but for C).

Do I have to add the @Entity mapping for classes B and C? Why?

anyway, thank you for you response

Jérôme


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