| I found a workaround. It's not beatiful, it's not magic and I'm not happy to have to use that, but it works. What I need to do is get the object reference wrapped by the Proxy. I used a CDI BeanManager to got EntityManger reference and then I was able to unwrap SessionImplementor.
@Inject
private BeanManager beanManager;
final Context injectionContext = this.beanManager.getContext(RequestScoped.class);
final Bean entityManagerBean = this.beanManager.resolve(beanManager.getBeans(EntityManager.class));
final EntityManager entityManager = (EntityManager) injectionContext.get(entityManagerBean);
final SessionImplementor session = entityManager.unwrap(SessionImplementor.class);
Another alternative is to use Hibernate 5.1.x, but the Java 8 features provided by Hibernate 5.2 as pretty nice. |