21.What is Callback in EJB?
Callback is a mechanism by which life cycle of an enterprise bean can be intercepted. EJB 3.0 specification has specified callbacks for which callback handler methods are to be created. EJB Container calls these callbacks. We can define callback methods in the ejb class itself or in a separate class. EJB 3.0 has provided many annotations for callbacks.
22.What are the callback annotations for stateless bean?
Following is the list of callback annotations for stateless bean:
@PostConstruct – method is invoked when a bean is created for the first time.
@PreDestroy – method is invoked when a bean is removed from the bean pool or is destroyed.
23.What are the callback annotations for stateful bean?
Following is the list of callback annotations for stateful bean:
@PostConstruct – method is invoked when a bean is created for the first time.
@PreDestroy – method is invoked when a bean is removed from the bean pool or is destroyed.
@PostActivate – method is invoked when a bean is loaded to be used.
@PrePassivate – method is invoked when a bean is put back to bean pool.
24.What are the callback annotations for message driven bean?
Following is the list of callback annotations for message driven bean:
@PostConstruct – method is invoked when a bean is created for the first time.
@PreDestroy – method is invoked when a bean is removed from the bean pool or is destroyed.
25.What are the callback annotations for entity bean?
Following is the list of callback annotations for entity bean:
@PrePersist – method is invoked when an entity is created in database.
@PostPersist – method is invoked after an entity is created in database.
@PreRemove – method is invoked when an entity is deleted from the database.
@PostRemove – method is invoked after an entity is deleted from the database.
@PreUpdate – method is invoked before an entity is to be updated in the database.
@PostLoad – method is invoked when a record is fetched from database and loaded into the entity.
26.What is a timer service in EJB?
Timer Service is a mechanism using which scheduled application can be build. For example, salary slip generation on 1st of every month. EJB 3.0 specification has specified @Timeout annotation which helps in programming the ejb service in a stateless or message driven bean. EJB Container calls the method which is annotated by @Timeout.
EJB Timer Service is a service provided by Ejb container which helps to create timer and to schedule callback when timer expires.
27.Which annoatation is used to inject an ejb into another ejb?
@EJB annotation is used to inject other EJB reference.
28.Which annoatation is used to inject an datasource into an ejb?
@Resource annotation is used to inject an datasource into an ejb.
29.Which annoatation is used to inject singleton services like timer service into an ejb?
@Resource annotation is used to inject singleton services like timer service into an ejb.
30.Which annoatation is used to inject SessionContext into an ejb?
@Resource annotation is used to inject SessionContext into an ejb.