tags:

views:

462

answers:

1

Hi, I have the following questions

  1. I have the '@Id' annotated field as part of my '@MappedSuperClass' and I am letting all my entities extend the MappedSuperClass.Now,how do I override the super class 'id' if I have to define a composite primary key for my entity...ie.How do I ask my entity to use its composite primary key annotated as @EmbeddedId instead of the @Id annotated field inherited from the MappedSuperClass? Will the @EmbeddedId annotation in my entity automatically over-ride the superclass's @Id ?

  2. I have made a few fields (which are shared by most of the entities in my schema) as part of my MappedSuperClass. Now how do I avoid those fields getting added as columns if few of the entities don't need them ?

Thanks.

+1  A: 

[...] How do I ask my entity to use its composite primary key annotated as @EmbeddedId instead of the @Id annotated field inherited from the MappedSuperClass? Will the @EmbeddedId annotation in my entity automatically over-ride the superclass's @Id ?

AFAIK, you can't. So don't inherit from your entity superclass in this case, use another entity superclass.

I have made a few fields (which are shared by most of the entities in my schema) as part of my MappedSuperClass. Now how do I avoid those fields getting added as columns if few of the entities don't need them ?

Well, again, don't inherit from the entity superclass that holds these fields and use another entity superclass.

Pascal Thivent