1

I have an abstract superclass that has JPA annotations on it mapping some of its fields. The class itself has the @MappedSuperclass annotation.

Can I specialize/add or change just one element of an inherited annotation without re-specifying the entire annotation?

2
  • If you need to do this it sounds like the annotations being used are abusing the intent of anotations. I've worked on something similar using annotations to add meta data to properties on get/set methods, sure enough we had to override methods simply to hide/change the annotation data. Commented Mar 4, 2010 at 18:09
  • 1
    Sorry, just saw the JPA reference. I personally think being able to set config in JPA annotaions is evil, sure it may save you some time but in the long run it's a deployment nightmare. Commented Mar 4, 2010 at 18:10

1 Answer 1

1

The only thing you can do with Annotations is to place an Annotation on an Annotation and have a library which understands this as a form of inheritance.

The problem is that if you re-specify the entire annotation, any library which expects MappedSuperclass will ignore it.

Sign up to request clarification or add additional context in comments.

1 Comment

Too bad for me. This means I am going to have to create a almost a dozen subclasses for no other reason than to tweak annotations. What's worse, most of the annotations are the same for all subclasses! I hate duplicate annotations even more than duplicate code.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.