Introduction to Callbacks and Callback Handlers in EJB3
The EJB 3.0 specification defines some callbacks, and allows you to handle these by implementing your own callback handlers. The callbacks defined for each bean are shown below:-
Stateless session bean callbacks
-
PostConstruct- is invoked when the bean is first created, after any dependency injection is done. -
PreDestroy- is invoked when the bean is removed from the pool or destroyed.
-
-
Message-driven bean callbacks
-
PostConstruct- is invoked when the bean is first created, after any dependency injection is done. -
PreDestroy- is invoked when the bean is removed from the pool or destroyed.
-
-
Stateful session bean callbacks
-
PostConstruct- is invoked when the bean is first created, after any dependency injection is done. -
PreDestroy- is invoked when the bean is removed from the pool or destroyed. It will happen before any@Removeannotated method is invoked. -
PostActivate -
PrePassivate
-
-
Entity bean callbacks
The callbacks are not compulsory, and you can define the ones you want to handle.-
PrePersist- Is invoked right before the entity is created in the database. Will cascade to all entities to which this operation is cascaded. -
PostPersist- Is invoked right after the entity is created in the database. Will cascade to all entities to which this operation is cascaded. -
PreRemove- Is invoked right before the entity is deleted in the database. Will cascade to all entities to which this operation is cascaded. -
PostRemove- Is invoked right after the entity is deleted in the database. Will cascade to all entities to which this operation is cascaded. -
PreUpdate- Takes place right before the database is updated. -
PostUpdate- Takes place immediately after the database has been updated. -
PostLoad- Takes place right after data has been loaded from the database and associated with the entity
Life Cycle Methods for an EJB 3.0 Stateless Session Bean
-



No hay comentarios.:
Publicar un comentario