Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Why EJBs?

 
Saeed Amer
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
EJBs are getting ridiculously complex and one cannot master them just by reading books or taking exam or attempting certain examples. Even if one is working with EJBs at work, it takes months to get a certain level of comfort.

So why use EJBs? Why not use SQLJ, JDO or even simple plain JDBC?

Regards,
Saeed Amer
[ July 26, 2005: Message edited by: Saeed Amer ]
 
Nicholas Cheung
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is because EJB containers provide more functionalities than those technologies you had specified. For example, in case there is an exception involved a series of DB operations, if one of them has been failed, the whole transaction should be rollback. Then, you have to code for handling such events. For EJB, containers will cater all stuffs for you.

Although it is very complex, EJB 3.0 has tried to simplify EJB via POJO and make use of the idea of Hibernate. Let's see the improvement of the new EJB generation.

Nick
 
Siripa Siangklom
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Saeed,

You get infrastructure services such as transactions, pooling, security, and so on from EJB containers. You can focus on business functionality.

Thanks,
Siripa
 
Barend Garvelink
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'd say the primary reason for using EJB is to get the distributed transactions. EJB is certainly not suitable for every situation (as is well-documented).
 
Roger Chung-Wee
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This could be interesting.
http://www.coderanch.com/t/316680/EJB-JEE/java/EJB-vs-Spring
 
Joao Vitor Guimaraes
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Barend Garvelink:
I'd say the primary reason for using EJB is to get the distributed transactions. EJB is certainly not suitable for every situation (as is well-documented).


For distributed transactions you have JTA and EJBs use it internally.

Spring provide some features, like declarative transaction through AOP that can use JTA too if you need.

As this thread is about "Why EJB's?" I'm mentioning Spring as a good alternative/complement that can be used in many projects.
 
Nicholas Cheung
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As this thread is about "Why EJB's?" I'm mentioning Spring as a good alternative/complement that can be used in many projects.

In certain sense, if any opensource framework looks good to J2EE, I guess SUN will try to adopt their features in the upcoming versions, like EJB 3.0 adopts the ideas from Hibernate.

So, don't worried too much, J2EE framework will be more and more mature.

Nick
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic