views:

454

answers:

1

When Using Dynamic Proxies, how do I access the underlying object's Annotations?

Specifically I'm annotating settings of a ORM object with @Column("client_id") and then making a Dynamic Proxy keep track of when the annotated setters are called, but...

It doesn't seem that the annotated proxy keeps any of the underlying annotations so short of performing reflection on every invocation, how do I make the proxy have the annotations of the class it's Proxying?

Thank you, Allain

+3  A: 

AFAIK, it depends on your bytecode injection lib. Also, remember that typically annotations are not inherited (imposed by the Java spec). If you want to access the original class, and are using CGLIB, you can use this snippet:

 if (Enhancer.isEnhanced(getClass())) {
    currClass = UnEnhancer.unenhance(getClass());
 } else {
    // else, let's get the original class directly
    currClass = getClass();
 }
Miguel Ping