Comment #12 on issue 201 by joshgr: AOP classes don't get the annotations of the superclass
http://code.google.com/p/google-guice/issues/detail?id=201
I've been very frustrated by this shortcoming myself: my team is using JPA/Hibernate with Guice. To facilitate a "rich domain model" (ie, domain-logic directly in our entity-classes), I'm using a Hibernate Interceptor to augment Hibernate's Entity-instantiation, and constructing the entity instances with a Guice Injector. This enables Guice AOP and injection in our Entity instances: we can annotate model-methods with @Transactional (a-la warp-persist), and we can @Inject dependencies into our Entities directly. Sweet!
This works beautifully, EXCEPT that the standard JPA method annotations for lifecycle-event observers (@PrePersist, @PreUpdate, etc) aren't retained on the Guice-enhanced entity instances. Surprise! This caused a subtle bug that only appeared when we added a guice MethodInterceptor to an existing entity class... Suddenly, our entity-lifecycle callbacks stopped being invoked! Thank goodness for integration-tests.
I'm currently building a workaround involving a class-level EntityListener that will look up-the-tree to find and invoke persistence-event annotations, but this is very cumbersome and, more importantly, doesn't feel like it should be *my* concern: Guice is constructing my objects and providing "magic" AOP, but the abstraction is leaking here.
If it's too expensive to perform method-annotation-preservation by default, it seems appropriate that the framework should at least support it *upon request*, as a binding configuration..?
Annotation-based tools and functionality continue to become more pervasive; I anticipate the impact of this subtle failure may become more common and expensive for guice-enhanced developers. Plz fix.
-- You received this message because you are subscribed to the Google Groups "google-guice-dev" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/google-guice-dev?hl=en.
