Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

DAO OR EJB  RSS feed

 
tariq shadid
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello there ,

i want to know when i have to use DAO With POJO or use EJB and if anybody know please can he give exmaple and resource about this issue

Tariq Shadid

JAVA DEVELOPER
 
Jeanne Boyarsky
author & internet detective
Sheriff
Posts: 37222
519
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tariq,
In general, you use EJB if you need services the container provides like security or transaction support. You can use session beans to wrap POJOs or entity beans for this benefit.

Note that in EJB 3.0, EJBs are annotated POJOs that provide these services.
 
Pratheep Nair
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In addition to whatever Jaene has pointed out, the main advantage of using EJBs is scalability. Even when you use EJBs, you will still use DAOs to talk to database. You may also use some other POJO objects as services between the EJBs and your DAOs. These services can handle your business logic. This gives a good level of abstraction. Thus if you decide to run your services outside the EJB container you can just take your POJO services and deploy them in a web container if you have your own custom framework to take care of whatever an EJB container provides. Bottomline is, if you are looking for a scalable architecture go for EJB. But remember anything good comes with a price...
 
Neerav Narielwala
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use DAO when you want a persistence layer without EJBs. You write all the Java/JDBC/SQL code.

Use entity bean when you need EJBs, which means your app is distributed, transactional, high availability, high throughput, clustered, etc.
 
Michal Glowacki
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'd like just to add that in my case I'm using DAOs for getting read-only data as they are about twice time faster than entity beans, espacially when i need to read data from 2-3 beans.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!