Question

I want to save history of changes, so in @PostUpdate i want to create new instance of another entity and save it, how do i pass EntityManager to that method?

Was it helpful?

Solution

You can get an instance of EntityManager just by retrieving it from the context as you would on any other:

1) Through injection in your class:

@PersistenceContext EntityManager em; // injected in your class

2) Using EntityManagerFactory:

EntityManager em = EntityManagerFactory.getEntityManager();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top