javaspringgenericshibernate-envers

How to make generic type of specifically annotated class?


I need to generify an interface to a class that is annotated to a specific annotation, say having the following entity class

@Entity
@Audited
class Record {
   private Long id;
   private String something;
   private String somethingElse;
}

which is audited with Hibernate Envers, I want to provide a service class that obtains some revision data. With something like

public interface AuditRecordService<E extends Audited> {
//
}

I know I can modify the Record class to extend an abstract class, something like:

@Entity
@Audited
class Record extends RevisionedEntity {
...

This works for me, but I want to avoid unnecessary extension, since it's already annotated with @Audited. Is it possible to reuse this annotation as a generic type?


Solution

  • Audited is an annotation, not a type. Annotations cannot be extended, so the only possible implementation of AuditRecordService<E extends Audited> would be AuditRecordService<Audited>, which would be pretty useless.