Skip to Main Content
Enterprise JavaBeans 3.1, 6th Edition
book

Enterprise JavaBeans 3.1, 6th Edition

by Andrew Lee Rubinger, Bill Burke
September 2010
Intermediate to advanced content levelIntermediate to advanced
766 pages
18h 35m
English
O'Reilly Media, Inc.
Content preview from Enterprise JavaBeans 3.1, 6th Edition

Callbacks on Entity Classes

You can have an entity bean instance register for a callback on any of these lifecycle events by annotating a public, private, protected, or package-protected method on the bean class. This method must return void, throw no checked exceptions, and have no arguments:

import javax.persistence.Entity;
import javax.persistence.PostPersist;
import javax.persistence.PrePersist;

/**
 * Represents an Employee which is able to receive JPA
 * events.
 */
@Entity
public class EntityListenerEmployee
{

   private String name;

   public String getName() { return name; }
   public void setName(final String name) { this.name = name; }

   /*
    * Event Listeners; fired by JPA and track state in the EventTracker
    */

   @PrePersist
   @SuppressWarnings("unused")
   private void prePersist(){ ... }

   @PostPersist
   @SuppressWarnings("unused")
   private void postPersist(){ ... }

   ...
}

When an event is triggered on a particular managed entity instance, the entity manager will invoke the appropriate annotated method on the entity bean class.

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Reinventing the Organization for GenAI and LLMs

Reinventing the Organization for GenAI and LLMs

Ethan Mollick
JavaServer Faces

JavaServer Faces

Hans Bergsten
EJB 3 Developer Guide

EJB 3 Developer Guide

Michael Sikora

Publisher Resources

ISBN: 9781449399139Errata Page