This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes EJB and other Java EE Technologies and the fly likes Understanding EJB's - Need insight Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Understanding EJB Watch "Understanding EJB New topic
Author

Understanding EJB's - Need insight

Ashok A Kumar
Greenhorn

Joined: Jul 01, 2010
Posts: 19
Hi All,
This is my first post in here, I'm an avid reader of javaranch for years but i didn't get an opportunity to post ( You all rock javascript:emoticon('');). I've started reading (as well as revisting) about ejb's ( Mastering EJB --> By Ed roman -- Amazing book) and i've got few questions in my mind.

1) what is the use of EJB's in real time? ( In a Complex web/enterprise applications)
2) Most of my friends (Those are working in J2EE Applications) are telling using EJB is a overhead and they didn't get chance to utilize the EJB's extensively, At the maximum they've tried stateless sessions bean.
3) If database persistency can be handeled by entity beans ( Correct me if i'm wrong), What is the need for hibernate?
4) Actually as per the EJB specification, It allows the programmer to concentrate on writing business logic rather worrying about system related issues.. is that right? If my application requires lot of transaction related issues is that good to allow the container to take care of the transaction mechanism or acheving it programmatically?


Got lot of questions though.. At this point getting insight and clarifications on above point would be helpful for me to move ahead on EJB's

Appreciate all your help on this.. javascript:emoticon('');

Sincerly

Ashok
Karthik Shiraly
Ranch Hand

Joined: Apr 04, 2009
Posts: 497
    
    5
Hi,


1) what is the use of EJB's in real time? ( In a Complex web/enterprise applications)
4) Actually as per the EJB specification, It allows the programmer to concentrate on writing business logic rather worrying about system related issues.. is that right?

Every app will have some application logic.
For ease of maintenance, it makes sense to split the app into multiple layers. Each layer is responsible for a particular aspect - example, a view layer has all the frontend UI code; a model layer has all the application logic classes that handle rules like "don't allow a withdrawal if account balance is <5000"; a data layer is responsible for interacting with databases on behalf of the model.

Sometimes, the model layer objects need to be distributed across multiple locations, maybe for performance or other deployment reasons.

Typically, most apps also require services like security - the model classes should prevent an unauthorized user from some operations, and this rule should be enforced across multiple machines in a distributed model.

Or those model classes may need to do transactions in a distributed environment.

Now, either each company who needs such services in its software can spend lots of effort and money designing and implementing all this from scratch. Use RMI design patters for distributed architecture; roll out their own security policies....imagine how much additional code is needed in each class (if you can't imagine, try writing a RMI client server app with your own security)....
OR
Use the J2EE EJB standard which provides all these. EJB is just a technology that provides secondary - but vital - services to model layer classes, so that companies can concentrate on their core application logic, and not on aspects like distribution, security and transactions.


2) Most of my friends (Those are working in J2EE Applications) are telling using EJB is a overhead and they didn't get chance to utilize the EJB's extensively, At the maximum they've tried stateless sessions bean.

Just depends on the project - perhaps their projects did not need the other EJBs, perhaps their project designers just did not know utility of other bean types. Message driven beans are used extensively and without fretting. Stateful session beans are useful in certain situations. Only entity beans suffered a bad reputation because they're complex to use and maintain, not to mention their performance and resource problems in certain situations.

But importantly, EJB 3 is a very different beast from EJB 2.1. If you're learning EJBs for future projects, learn and use EJB 3.0 and above, not EJB 2.1.


3) If database persistency can be handeled by entity beans ( Correct me if i'm wrong), What is the need for hibernate?

Short answer is, the way EJB 2.1 was designed was simply overengineering for most projects, leading to code maintenance, performance and resource problems. The community came up with alternatives to make their lives easier - mostly requiring only simple java classes or POJOs (plain old java objects) - like spring framework, hibernate, and JPA.
You can just write simple plain java classes and still enjoy the kind of enterprise services that J2EE set out to provide.
JavaEE5, EJB 3 and JPA are definite improvements over earlier J2EE standards, and more closely resemble these POJO frameworks. They're also gaining more and more acceptance since they're standards, unlike the proprietary POJO frameworks.

Rod Johnson's "Expert one-on-one J2EE design and development" is a great book if you want to learn just what all is wrong with J2EE 1.4 and earlier. He's the originator of spring framework. Here's a relevant article where he explains some aspects http://www.theserverside.com/news/1364653/Expert-One-on-One-J2EE-Design-and-Development-Interview-with-Rod-Johnson.


If my application requires lot of transaction related issues is that good to allow the container to take care of the transaction mechanism or acheving it
programmatically?

Unfortunately, there is no simple answer. CMPs were meant to make development and maintenance easier, and BMPs were meant to give the flexibility to systems that really needed it. That was the intention....but somewhere, the message was lost and both became a mess. Read Rod Johnson's book for very detailed explanations.
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10069
    
163

Karthik Shiraly wrote:

If my application requires lot of transaction related issues is that good to allow the container to take care of the transaction mechanism or acheving it
programmatically?

Unfortunately, there is no simple answer. CMPs were meant to make development and maintenance easier, and BMPs were meant to give the flexibility to systems that really needed it. That was the intention....but somewhere, the message was lost and both became a mess. Read Rod Johnson's book for very detailed explanations.


Did you mean CMT and BMT? I haven't read that book, so I don't know what the mess is with CMT and BMT.

[My Blog] [JavaRanch Journal]
Ashok A Kumar
Greenhorn

Joined: Jul 01, 2010
Posts: 19
@karthik,

Thanks a lot for the wonderful and detailed explanation on EJB's. I will read the book that you've suggested and i will keep you posted. if you could give much more explanation about CMT and BMT, that would defantely help. Thanks again..

 
Consider Paul's rocket mass heater.
 
subject: Understanding EJB's - Need insight