Extending a annotaded class
hi,
I'm facing the following problem: I have some objects extending an abstract class, and some of them has a kind of template classes, well, I'd like to know if I could put some annotations on these templates. I've tried, but didn't work.
Is there some annotation to "say" to get the annotations in the super class? Or another solution.
@Entity
publicabstractclass Base<Textends Serializable>implements
Serializable{
private T id =null;
...
@Id
public T getId(){
return id;
}
...
}
@Table(name ="company")
publicclass Companyextends Base<Integer>{
private String name =null;
@Column(length = 40)
public String getName(){
return name;
}
...
}
Best regards,
Rodrigo Souza
Brazil - SP
null
# 1
if @Inherited meta-annotation is declared in the definition of an annotation it can be found via the super class
http://java.sun.com/j2se/1.5.0/docs/api/java/lang/annotation/Inherited.html
if not, you can create your own with the meta-annotation
although, philosophically, this can be seen as a departure from the declarative nature of annotations
you can always decorate each concrete class with the appropriate annotations (maybe a Declarative Hardliners approach)
# 2
Fixed putting this annotation @MappedSuperclass in the super class
http://forum.hibernate.org/viewtopic.php?p=2352530#2352530
http://java.sun.com/javaee/5/docs/api/javax/persistence/MappedSuperclass.html
Code following
@MappedSuperclass
public abstract class Base<T extends Serializable> {
private T id = null;
@Id
public T getId() {
return id;
}
}
@Entity
@Table(name = "company")
public class Company extends Base<Integer> {
private String description = null;
@Column(length = 1)
public String getDescription() {
return description;
}
}