Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

10. Entity Callbacks and Listeners > 10.1. Callback Events

Callback Events

A certain annotation represents each phase of an entity’s life cycle:

@javax.persistence.PrePersist 

@javax.persistence.PostPersist 

@javax.persistence.PostLoad 

@javax.persistence.PreUpdate 

@javax.persistence.PostUpdate 

@javax.persistence.PreRemove 

@javax.persistence.PostRemove 

The @PrePersist and @PostPersist events have to do with the insertion of an entity instance into the database. The @PrePersist event occurs immediately when the EntityManager.persist( ) call is invoked or whenever an entity instance is scheduled to be inserted into the database (as with a cascaded merge). The @PostPersist event is not triggered until the actual database insert.

The @PreUpdate event is triggered just before the state of the entity is synchronized with the database. The @PostUpdate event happens after. This synchronization could occur at transaction commit time, when EntityManager.flush( ) is executed, or whenever the persistence context deems it necessary to update the database.


  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint