Discussion:
JPA entity with custom annotations
Travis Collins
2016-08-14 14:51:51 UTC
Permalink
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?
--
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.
Stephan Classen
2016-08-15 12:27:30 UTC
Permalink
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.
Post by Travis Collins
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?
--
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
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
<https://groups.google.com/d/msgid/google-guice/7c493f80-dcf4-427f-9706-36283ae7160d%40googlegroups.com?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout.
--
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/fa9eb442-483f-71f2-6300-3f2f3685b840%40gmx.ch.
For more options, visit https://groups.google.com/d/optout.
Loading...