Will there be a performance improvement if I remove the entity bean (finder methods) and introduce the DAO layer instead. I want to do this mainly for reading data from the DB. I have a process in my project which has around 15 entity beans finder call in the flow, so if I remove the Entity beans or introduce a DAO and leave the entity beans as it is will there be a significant improvement in the performance ? I am using EJB 2.1.
问题:
回答1:
Retrieving data by using Entity Bean finders loads all of the attributes for the entity, even when you might only need the value of one of them for the task at hand. So, indeed, EJB finders methods have overhead and this is especially true when retrieving large data sets (not even to mention when you are invoking 15 of them).
So, to retrieve large read-only data sets, it may indeed be preferable to talk to the database directly from the Session Bean (I guess that you have a Session Bean facade) using JDBC API. This pattern is known as Fast Lane Reader if I remember well.
Just keep in mind that implementations of this pattern sacrifice data consistency for performance, since queries performed at the raw JDBC level do not "see" pending changes made to business information represented by Enterprise Beans.