DAO is used to interact with database and other type of storages
where as EJB are your business domain entities. Generally they are used in combination of each other except when you are using CMP type of beans.
The selection criteria is not based on no. of hits. and EJB's are the way of simplifying and brining a modular type of approach in your design. If they are
architected properly, then I don't see a reason why they are not scalable. I guess you should read java documentation and try reading Core J2ee patterns and Masering EJB2, that's where I am learning from.
I hope this helps.
EJBs are no doubt scalable. Usually you access data using
3. Sessions beans with JDBC.
Compare it to DAO that can help you to form your own persistence mechanism and policy not only to RDBMS but to any kind of data store. be it XML/file system. But CMP/BMPs can't help you with that as they stick only to RDBMS.
cant remmeber the link but there was some article related to what you are looking at serverside.com
DAO is a design pattern that can be followed to encapsulate database access from the rest of your code.
i tend to use DAOs reguardless of whether or not i am using cmp, straight jdbc, etc just b/c i like to keep that code centralized in one location and it allows me to change the internals w/o affecting multiple source files.
Alternatively, if you want ease of development and neat code (therefore, easy to debug code). You should use:
1. Vanilla Hibernate
2. BMP (replace JDBC with Hibernate)
3.Session Beans with Hibernate
Trust me, you'll save yourself a lot of trouble steering away from JDBC and CMP beans.
99% of the time, you don't need to code JDBC, except in certain batch processing scenarios.
Take the red pill ---> http://www.hibernate.org/
-Great Imhotep _/"""\_/"""\_/"""\_
I think that when when more objects are created it is better to use DAO else use Entity Bean.
When you go for :"Select * from Employee".
In this it will create a lot of EJBObjects.
Instead of that use DAO.
In case of inserting, updating and deleting use Entity Beans.
Hope it is right.
can any one please tell mewhen to use DAO or EJB
is the selection also depends on No of hits.
also are EJB not scalable
As Sachin said, use DAO when the application is primarily of reporting type ( mostly selects). When you require a lot of inserts and updates and real time persistance, also when your java objects need to reflect the state of database objects go for Entity EJBs.
you can find a good story on the pro's and con's on pages 76-80 of "EJB Design Patterns of Floyd Marinescu" free downloadable at