Java Reference
In-Depth Information
public class EmployeeEntityListener {
@Resource(name="jndi/AcmeMail")
javax.mail.Session mailSession;
@PrePersist
public void prePersist(Employee employee){
System.out.println("The following Employee enity is about to be persisted: "
+ employee.getLast());
// use the mail session
}
}
To register this entity listener on the entity, utilize the @EntityListeners annotation on the entity itself, as
follows:
@Entity
@Table(name = "EMPLOYEE")
@EntityListeners(EmployeeEntityListener.class)
public class Employee implements Serializable {
...
}
Summary
Object-relational mapping is a natural way of mapping database tables to Java objects. Coding against Java objects,
rather than writing standard SQL to work with databases, can be beneficial for a number of reasons. Not only does
it make an application easier to maintain, but it also makes it less error prone. The JPA 2.1 release includes some
incremental enhancements that help to make it even more productive and enable even more features, such as the
ability to utilize stored database procedures more easily. Furthermore, schema management has never been easier
than it is now with the new JPA schema generation. Although the JPA 2.1 release is incremental, it brings forth many
improvements that help to solidify object-oriented development for Java Enterprise applications.
 
Search WWH ::




Custom Search