Primary Keys for Bean-Managed Persistence

You specify the primary key class in the entity bean’s deployment descriptor. In most cases, your primary key class will be a String, an Integer, or some other class that belongs to the J2SE or J2EE standard libraries. For some entity beans, you will need to define your own primary key class. For example, if the bean has a composite primary key (that is, one composed of multiple fields), then you must create a primary key class.

The Primary Key Class

The following primary key class is a composite key—the productId and vendorId fields together uniquely identify an entity bean.

 public class ItemKey implements java.io.Serializable { public String productId; public String vendorId; public ItemKey() { ...

Get J2EE™ Tutorial, The 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.