With Hibernate validation, can I query the entity being validated?

寵の児 提交于 2019-12-05 19:00:28

Inspired by this post and the knowledge that it is never OK to call/use the same session in any callback methods that are triggered from the session, I managed to solve the problem quite simply by getting hold of my EntityManagerFactory, which in turn lets me get an EntityManager, which gives me a new Session. Now I can use this to do the query.

EntityManager em = emFactory.createEntityManager();
session = (Session) em.getDelegate();
Query query = session.createQuery(...

NOTE: That from the EntityManager docs, getDelegate() is implementation specific. I'm using tomcat and hibernate, and it work's well.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!