Implementing a BMP Entity Bean

Implementing an Entity bean involves providing an implementation for the methods of the javax.ejb.EntityBean, and corresponding methods for each method in the local-home and local interfaces.

Implementing javax.ejb.EntityBean

The setEntityContext() method is the preferred place to perform JNDI lookups, for example to acquire a JDBC DataSource reference. Listing 6.5 shows how this is done for the JobBean code.

Listing 6.5. JobBean.setEntityContext() Method
 package data; import javax.ejb.*; import javax.naming.*; import javax.sql.*; // imports omitted public class JobBean implements EntityBean { public void setEntityContext(EntityContext ctx) { this.ctx = ctx; InitialContext ic = null; try { ic = new InitialContext(); ...

Get Sams Teach Yourself J2EE™ in 21 Days, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.