Entity listeners - rafalkieras/jpa-kss GitHub Wiki
#Entity listeners
Entity listeners are used to react on certain events that can occur during managing the entities. In JPA there are 7 events defined:
- @PostLoad
- @PostPersist
- @PostRemove
- @PostUpdate
- @PrePersist
- @PreRemove
- @PreUpdate
Those annotations can be applied to methods of an entity class, a mapped superclass, or a callback listener class. A single class must not have more than one lifecycle callback method for the same lifecy- cle event.
Default entity listeners — entity listeners that apply to all entities in the persistence unit. They can be specified by means of the XML descriptor.
A runtime exception thrown by a callback method that executes within a transaction causes that transaction to be marked for rollback. No further lifecycle callback methods will be invoked after a runtime exception is thrown.