JPA entity with custom annotations

103 views
Skip to first unread message

Travis Collins

unread,
Aug 14, 2016, 10:51:55 AM8/14/16
to google-guice
I'm running a small test that uses a Guice managed JPA context. It's working very well. 

I have created some custom annotations on the entity classes. These annotations are generally used to validate values on setters. I'm using the Guice binder.bindInterceptor(...) method to intercept method calls and validate values. 

When I use a Guice Provider<> to instantiate new instances of these classes, the annotation interceptors are working correctly. 

However, when I retrieve a JPA object from the persistence context, the custom annotation interceptors are not being called. For example, if I get an entity instance using the JPA entity manager, and then try to set an invalid value on that object - the interceptor is not called and the invalid value is allowed. 

I have verified that the entityManager being used is Guice provided. 

Any ideas?

Stephan Classen

unread,
Aug 15, 2016, 8:27:34 AM8/15/16
to google...@googlegroups.com

Yes the entityManager is created by guice.

But the entities that you retrieve from the DB are not created by guice and therefore the interceptor does not work.

--
You received this message because you are subscribed to the Google Groups "google-guice" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-guice...@googlegroups.com.
To post to this group, send email to google...@googlegroups.com.
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-guice/7c493f80-dcf4-427f-9706-36283ae7160d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages