Hi, I am supporting a project that is exploring a user defined metadata driven data model within our platform (from both our own custom annotations that carry our metadata and a UI). We have opted for JPA/Hibernate persistence in tandem with Javassist for building proxy classes. For Java developers, we are hoping to alleviate the need to always specify JPA or Hibernate annotations (or to even be aware of them with their POJOs) - so either we use reflection to generate mapping files, or provide default annotations. However, it appears Hibernate does not scan beyond first level annotations. Does anyone know a work-around for this, or if this is a feature that could be added? Example below:
@Component @Entity @Target(TYPE) @Retention(value=RUNTIME) public @interface MyAnnotation {
String name(); }
@MyAnnotation(name="test") public class MyClass {
}
In this example, Spring will pick up MyClass as a component and register it within its bean factory, as we would like. Now we can easily scan and process any of our own annotations using Spring's classes. However, @Entity, or any other JPA/Hibernate annotations, do not appear to be processed by Hibernate. I looked a little deeper into it and saw the Hibernate's ReflectionManager uses a class called AnnotationReader that ultimately checks Java's AnnotatedElement isAnnotationPresent which ends up only looking at first level annotations and not any annotations of the annotations like Spring does.
It would be nice if we could either transitively discover JPA/Hibernate annotations that are on our custom annotations, or to have some hook into the AnnotationReader or way to override default Configuration behavior to reflectively read the full annotation graph. Is this possible?
Does anyone have any more information about this, or a work around? Thanks a lot for any help or feedback.
|