File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes EJB and other Java EE Technologies and the fly likes Entity Bean Vs. DAO Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Entity Bean Vs. DAO" Watch "Entity Bean Vs. DAO" New topic
Author

Entity Bean Vs. DAO

kumar santosh
Greenhorn

Joined: Apr 05, 2004
Posts: 2
I am not able to understand fully why under certain criteria(s), one should decide to use entity beans over DAO's wrapper by session beans or
DAOs over Entity Beans.
I would welcome input from expert on using entity beans in a project.
I would be extremly thankful if someone can give me an example, referring to some live project / application where people have used entity beans/DAO and have benefitted.
What all requirements in an application demand using entity beans or DAOs??
Thanks in advance.
eammon bannon
Ranch Hand

Joined: Mar 16, 2004
Posts: 140
Personally, I would never use entity beans. Particularaly as there are other simpler and better alternatives (Hibernate springs to mind). Why avoid entity beans?
- EJBQL is a limited subset of SQL, and lacks some commonly used functionality.
- they are more complex than POJOs.
- you are forced to use EJBs to access your entity beans, whether it is appropriate or not.
- they tend to perform worse than a POJO DAO framework.
- they are not a portable as the specs claim - most advanced functionality tends to be container specific.
- JDO offer all and more of their functionality anyway, so I think even Sun sees them as having a limited life time.
- they are a bad choice performance-wise in applications where the most common DB operation are reads.
- containers using them can try to reimplement very well understood RDBMS functionality in the application layer, and get no where close to the sort of performance you get in the DB.
I still am yet to see them deployed successfully in a production application.
kumar santosh
Greenhorn

Joined: Apr 05, 2004
Posts: 2
Thank you..
Dave Cronin
Ranch Hand

Joined: Apr 25, 2003
Posts: 114
There are trade-offs either way. There are three options:
session beans with DAOs,
entity beans with DAOs and BMP (Bean Managed Persistence)
or entity beans using CMP (Container Manager Persistence).
With DAOs you have to know both how to use JDBC well (not as easy as it seems) and how to use SQL. It is true that it gives you more control, and some projects use it for that reason. However entity beans with CMP has advantages of not needing to write database access code. The EJB container can optimise the beans in ways that it cannot using DAOs. Effectively the container writes its own DAOs and can handles them with optimisations like read-only, caching, finder access and more. Also most container provide useful extensions to EJBQL. So it depends what you want to do in the end.
I think comparisons need solid benchmarks - anyone have a good list?


Dave Cronin
SCJP, SCWCD, SCBCD
 
 
subject: Entity Bean Vs. DAO
 
Similar Threads
Separate db details from classes
CMP and DAO...
what comes first, the DAO or EJB?
DAO vs. Entity Beans
Implenting Data Access Object (DAO)