- Java EE 8 and Angular
- Prashant Padmanabhan
- 203字
- 2021-07-02 19:22:36
Entity listeners
The listeners can be put to use for performing interception on entity life cycle operations. We can also inject CDI managed beans into an entity listener for performing any additional processing. Here are the seven life cycle callback annotations that can be used:

The Task entity has an entity listener associated with it, thus during its life cycle events, the listener callback methods would be invoked. If there is more than one listener, then the invocation is done in the order of the listener declaration:
@Entity
@Table(name="task_detail")
@EntityListeners({TaskAudit.class})
public class Task extends MappedSuperEntity {
// code omitted
}
During each life cycle event of the Task entity, our TaskAudit class methods would be invoked, which are listening to the event. Thus, to listen to the post persist event, the following code declares a trackChanges method with the @PostPersist annotation:
public class TaskAudit {
@PersistenceContext private EntityManager em;
@PostPersist public void trackChanges(MappedSuperEntity entity)
{ ... }
}
While the listeners are handy to use for simple cases, they fall short for handling more complex requirements. There are modules, such as Hibernate Envers, which provide support for auditing capabilities with more capable features, but these are not part of the standard JPA specification.
- Java系統分析與架構設計
- 機器學習系統:設計和實現
- Java高并發核心編程(卷2):多線程、鎖、JMM、JUC、高并發設計模式
- Visual FoxPro程序設計教程
- Leap Motion Development Essentials
- Clojure for Domain:specific Languages
- PhpStorm Cookbook
- Learning OpenStack Networking(Neutron)
- HTML5從入門到精通 (第2版)
- Python圖形化編程(微課版)
- INSTANT Yii 1.1 Application Development Starter
- Wearable:Tech Projects with the Raspberry Pi Zero
- Koa與Node.js開發實戰
- 基于Docker的Redis入門與實戰
- TensorFlow.NET實戰