O'Reilly logo

Enterprise JavaBeans, Fourth Edition by Richard Monson-Haefel, Bill Burke, Sacha Labourey

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

The ShipBean

The ShipBean defined for this chapter uses JDBC to synchronize the bean’s state to the database. In reality, an entity bean this simple could easily be deployed as a CMP bean. The purpose of this chapter, however, is to illustrate exactly where the resource-access code goes for BMP and how to implement it. When learning about bean-managed persistence, you should focus on when and where the resource is accessed in order to synchronize the bean with the database. The fact that we are using JDBC and synchronizing the bean state against a relational database is not important. The bean could just as easily be persisted to some legacy system, to an ERP application, or to some other resource that is not supported by your vendor’s version of CMP.

Here is the complete definition of the ShipBean:

package com.titan.ship; import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.NamingException; import javax.ejb.EntityContext; import java.rmi.RemoteException; import java.sql.SQLException; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.DriverManager; import java.sql.ResultSet; import javax.sql.DataSource; import javax.ejb.CreateException; import javax.ejb.EJBException; import javax.ejb.FinderException; import javax.ejb.ObjectNotFoundException; import java.util.Collection; import java.util.Properties; import java.util.Vector; import java.util.Collection; public class ShipBean implements javax.ejb.EntityBean { public Integer ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required