4.6. Design Guidelines and Patterns

We have added a level of complexity to the example in this chapter by including an Enterprise Java Bean that accesses a database. The Music EJB can be a stateless session bean because it accesses the database in a read-only capacity.

DAO Pattern

Our first implementation keeps things as simple as possible by implementing database calls as private methods inside the bean implementation code. The trade-off between simplicity and lack of flexibility means that our code is “hard wired” to access a particular vendor's database. The second version uses the Data Access Object (DAO) Pattern to solve this lack of flexibility. Our approach is to create an interface that the bean implementation code invokes, and to write ...

Get Enterprise JavaBeans™ Component Architecture: Designing and Coding Enterprise Applications 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.