Creating View Objects

One of the most common patterns you see in three-tiered applications is the use of view objects. Remember, you want to reduce the number of calls you make from the client to the EJB container. If you need to retrieve a large number of fields from an EJB, either a session bean or an entity bean, you want to retrieve the values with a single method call.

You package all the values you want into a view class, which contains all the data items you want to retrieve. For example, Listing 12.1 shows a PersonView class holding all the data for a Person bean.

Code Listing 12.1. Source Code for PersonView.java
 package usingj2ee.addressbook; public class PersonView implements java.io.Serializable { public String firstName; public ...

Get Special Edition Using Java™ 2 Enterprise 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.