Been struggling with this. I must have screwed up the logic that
mixes-and-matches annotations from the implementation class with
annotations from the interface.
The problems with JPA are caused by this code from CommitAfterMethodAdvice:
private EntityTransaction getTransaction(final Invocation invocation)
{
final PersistenceContext annotation = invocation
.getMethodAnnotation(PersistenceContext.class);
EntityManager em = JpaInternalUtils.getEntityManager(manager,
annotation);
if (em == null)
return null;
return em.getTransaction();
}
The annotation is always null. Tracing with the debugger shows that
the method being invoked is a method on the Plastic Proxy class.
What I'm having trouble figuring out is why things worked when using
ClassFactory and not PlasticProxyFactory. Did I miss some code
somewhere that copied annotations from the interface into the proxy?
Normally, when you look at a method of a class, you see just the
annotations on that method, even if the method itself is an
implementation of an interface method that does have annotations:
public class Experiment
{
public interface Foo
{
@Deprecated
void foo();
}
public static class FooImpl
{
public void foo()
{
}
}
public static void main(String[] args) throws SecurityException,
NoSuchMethodException
{
System.out.println("Foo : " +
Foo.class.getMethod("foo").getAnnotation(Deprecated.class));
System.out.println("FooImpl: " +
FooImpl.class.getMethod("foo").getAnnotation(Deprecated.class));
}
}
Output:
Foo : @java.lang.Deprecated()
FooImpl: null
... I wonder if it is not too late to find a way to expose method
annotations via the AnnotationProvider interface; this would make it
much easier, as we already have AnnotationProvider and idea like
AnnotationProviderChain. It would be very nice if we could move away
from copying annotation from one class to another.
--
Howard M. Lewis Ship
Creator of Apache Tapestry
The source for Tapestry training, mentoring and support. Contact me to
learn how I can get you up and productive in Tapestry fast!
(971) 678-5210
http://howardlewisship.com
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]