@PreUpdate and @Prepersist in hibernate/JPA (using session)

Now it seems that those interpreters are not been executed, with little search i found out that it’s suitable using entityManager.

Yes, the JPA callbacks won’t work if you’re using the Session API.

So I’ll like to know if is there a SIMPLE way around my problem, meaning having @PrePersist or @PreUpdate or even other workaround to set the lastModified field still using session

To my knowledge, there is no simple way around (if you’re using Spring, MAYBE have a look at this post though).

My suggestion for an Hibernate based solution would be to use events (and one or more interface(s)). Check Hibernate and last modified date for an example.

Leave a Comment