---------- Forwarded message ---------- From: Igor Drobiazko <[email protected]> Date: Wed, Apr 20, 2011 at 10:14 PM Subject: Re: JPA / method annotations To: Howard Lewis Ship <[email protected]>
I would hate to move away from copying annotation to proxies. It would definitely break some of the existing apps. It would also a very big limitation for creating integrations with libraries which need to read annotations from classes. A good example a REST libs. If I recall it correctly, when implementing the copying annotations with Javassist there was an issue with the abstract class named AbstractInvocation. It doesn't implement the getMethodAnnotation method because it is generated somewhere. For components it is in InternalClassTransformationImpl. I don't recall the place for the service layer. Might it be the issue with plastic? On Wed, Apr 20, 2011 at 9:14 PM, Howard Lewis Ship <[email protected]> wrote: > 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 > -- Best regards, Igor Drobiazko http://tapestry5.de -- Best regards, Igor Drobiazko http://tapestry5.de
