Following scenario:
{code:java} public class MyService { @Inject private EntityManager em; // injects a WELD proxy
public void test() { em.unwrap(SessionImplementor.class).getFactory(); } } {code}
Calling {{MyService#test}} results in a ClassCastException: {noformat} java.lang.ClassCastException: org.jboss.weldx.persistence.EntityManager$470189163$Proxy$_$$_WeldClientProxy cannot be cast to org.hibernate.engine.spi.SessionImplementor {noformat}
This is due to becuase the condition at {{org.jboss.weld.bean.proxy.ProxyMethodHandler:103}} , causes the method handler returns {{self}} instead of {{this}}. The return type of {{EntityManager#unwrap}} is unbounded generic so {code:java} thisMethod.getReturnType().isAssignableFrom(self.getClass())) {code} always is true.
|