Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想保存更改的历史记录,所以在@PostUpdate 我想创建另一个实体的新实例并保存它,我如何将 EntityManager 传递给该方法?
您可以通过从上下文中检索它来获取 EntityManager 的实例,就像在任何其他实例上一样:
1)通过在您的课程中注入:
@PersistenceContext EntityManager em; // injected in your class
2)使用EntityManagerFactory:
EntityManager em = EntityManagerFactory.getEntityManager();