I've solved this problem. I've opened jpa specification 2.1 and found : *In general, the lifecycle method of a portable application should not invoke EntityManager or query operations, access other entity instances, or modify relationships within the same persistence context[46]. [47] A lifecycle callback method may modify the non-relationship state of the entity on which it is invoked.* And in Java Persistence with Hibernate book I've read that session in Listener is in fragile state. There is some advice: open a new session - sessionFactory.openSession(); But as for me I use Spring Framework and I've done my own workaround : I've just invoke in Listener my method from some service which is annotated @Transactional(propagation=Propagation.REQUIRES_NEW) - it means a new transaction and new session will be created respectively.
|