Data Access in J2EE apps


Data access is vital to enterprise apps. Often the performance of the data source and the strategies used to access it will dictate the performance and scalability of a J2EE app. One of the key tasks of a J2EE architect is to achieve a clean and efficient interface between J2EE business objects and data source. As we shall see, it's important to decouple business logic components from the details of data access. The EJB specification provides entity beans to achieve the necessary abstraction. However, the entity bean model isn't always appropriate, and there are other techniques we can use to achieve this objective without committing to it. This chapter takes a high-level view of the practical data modeling and data access choices facing J2EE architects and developers, paying special attention to the common problem of Object-Relational (O/R) mapping when using a relational database. It concludes by developing a data access strategy for our sample app. In the following two chapters, we'll look more closely at specific data access strategies. These strategies are the subject of religious debate among J2EE developers. We'll take a pragmatic approach, looking at how best to achieve results in real apps.


A disclaimer – 1 can't tell you everything you need to know about data access in J2EE apps. This requires expert knowledge of the underlying data sources you work with. For example, is the aim efficient and reliable access to an ODBMS or an RDBMS? Access to Oracle, DB2, or Sybase? There is no satisfactory "one size fits all" solution unless data access requirements are trivial.

By the end of this chapter you should be convinced that J2EE developers need a strong understanding of database technology, and should be prepared to seek specialist advice when necessary.