Submit web site - CHAPTER 1 Understanding object/relational persistence 1.2.5 The problem

CHAPTER 1 Understanding object/relational persistence 1.2.5 The problem of data navigation There is a fundamental difference in the way you access data in Java and in a relational database. In Java, when you access a user s billing information, you call aUser.getBillingDetails().getAccountNumber() or something similar. This is the most natural way to access object-oriented data, and it s often described as walking the object network. You navigate from one object to another, following pointers between instances. Unfortunately, this isn t an efficient way to retrieve data from an SQL database. The single most important thing you can do to improve the performance of data access code is to minimize the number of requests to the database. The most obvious way to do this is to minimize the number of SQL queries. (Of course, there are other more sophisticated ways that follow as a second step.) Therefore, efficient access to relational data with SQL usually requires joins between the tables of interest. The number of tables included in the join when retrieving data determines the depth of the object network you can navigate in memory. For example, if you need to retrieve a User and aren t interested in the user s billing information, you can write this simple query: select * from USERS u where u.USER_ID = 123 On the other hand, if you need to retrieve a User and then subsequently visit each of the associated BillingDetails instances (let s say, to list all the user s credit cards), you write a different query: select * from USERS u left outer join BILLING_DETAILS bd on bd.USER_ID = u.USER_ID where u.USER_ID = 123 As you can see, to efficiently use joins you need to know what portion of the object network you plan to access when you retrieve the initial User this is before you start navigating the object network! On the other hand, any object persistence solution provides functionality for fetching the data of associated objects only when the object is first accessed. However, this piecemeal style of data access is fundamentally inefficient in the context of a relational database, because it requires executing one statement for each node or collection of the object network that is accessed. This is the dreaded n+1 selects problem. This mismatch in the way you access objects in Java and in a relational database is perhaps the single most common source of performance problems in Java applications. There is a natural tension between too many selects and too big
If you are looking for affordable and reliable webhost to host and run your business application visit our ftp web hosting services.