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