Re: Usage of Data Access Object and Entity beans
Tuesday, November 25, 2003 04:29 AM
Well, both the designs are valid. I think this is really about the evolution of EJBs and DAO.
DAO provides an easy-to-use, clean interface to the data access. We can use this pattern to encapsulate the JDBC logic attached with the access of a particular data(db/table). Now this can be used from the 'direct' jdbc clients or BMP entity beans, as and when required.
However, with the CMPs taking the lead of the entity bean development - this advantage becomes useless. u dont need direct jdbc code to implement CMPs. So, where do u utilize DAO? DAO's are still useful, where you need a 'fast-lane-reader' sort of code. At some places, EJB-QL of the CMP is simply not sufficient and you would like to use direct jdbc for more controlled operations. Unfortunately, this means that the clients of the data tier (Servlet/Session Bean), need to talk with the entity beans as well as DAOs, depneding upon the operation required. This is where the next pattern for DAO is useful. DAO can provide 'direct-access' methods as well as proxy methods for the CMP beans.. this way the clients of the data tier have to understand one interface only..
so, ultimately it boils down to one thing: are u using BMP or CMP.. and everything else is positioned accordingly :)