There is another option, in which many tricks are involved, but at least it does not need reflection, which will give you the opportunity to check the compilation time:
public Connection getConnection(final EntityManager em) { HibernateEntityManager hem = (HibernateEntityManager) em; SessionImplementor sim = (SessionImplementor) hem.getSession(); return sim.connection(); }
You could even make it “prettier” with a few instanceof checks, but the version above works for me.
Stefan Haberl Sep 06 2018-12-12T00: 00Z
source share