Java Reference
In-Depth Information
persistence context will be dissociated from the transaction to which it was enlisted.
You need to call the EntityManager.joinTransaction() method again to en-
list the dissociated persistence context.
Entity
An entity listener is a simple Java class (not an entity), which allows you to define
the lifecycle callback methods that can be invoked for the lifecycle events of one or
many entities. The JPA 2.1 Specification adds to these classes the support of CDI
injection and the ability to define @PostConstruct and @PreDestroy lifecycle
callback methods. These methods are respectively called after the dependency in-
jections and before the destruction of the entity listener. The following code presents
an entity listener that has the post construct and pre destroy methods with an EJB
injection . It is followed by code that shows how to associate an entity listener to an
entity.
public class LogEntityListener {
@EJB
BeanLoggerLocal beanLogger;
@PrePersist
public void prePersistCallback(Object entity){
beanLogger.logInformation(entity);
}
@PostConstruct
public void init(){
System.out.println("Dependency injected
inLogEntityListener");
}
@PreDestroy
public void destroy(){
System.out.println("LogEntityListener will
be destroy");
}
}
Search WWH ::




Custom Search