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

EJB an Overhead?

 
Abubacker Siddik
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys,

I had a peculiar doubt that why do we all the way need an EJB?. After all, its making code verbose. What are all the things we can do in EJB can be done with other options like Hibernate and Struts or Spring framework that can also run in non-managed environment. In the J2EE environment, EJB is safe, secure and transactional. But there are other ways to achieve these features..still why do we need an EJB.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

After all, its making code verbose. What are all the things we can do in EJB can be done with other options like Hibernate and Struts or Spring framework that can also run in non-managed environment.

A comparison between EJB and Struts is pointless, they share no common functionality. I would use Hibernate with EJBs (or at least, a JPA provider) so that code would be pretty much identical in either deployment. Is Spring less verbose than EJB3?

 
Stu Quinn
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It depends entirely upon what you are doing. Your question implies you desire to keep everything as simple as possible, which is good. There is a good book addressing this "Faster, Better, Lighter Java". I would stick with Tomcat if it did everything I needed, however moving to an application server has made our lives easier because it is better suited to support the work we are doing. In particular it is easier to manage more complex applications that rely on multiple underlying projects. It has also allowed us to move to a service oriented architecture utilizing RMI/IIOP and to integrate easily with other applications such as JBPM.

Good luck,
Stu

 
Abubacker Siddik
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Guys,

You are right..that i cant make everything as simple as possible. What i am saying is that what a session bean is doing in an Enterprise application can be written in Struts Action class..I can use APIs to give its transactional and security issues..isnt it?
Why we need an session bean to wrap up our code and looking up JNDI code to get the service..isnt it an overhead?? thats i am asking guys..

Or im entirely wrong understanding these things...
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

What i am saying is that what a session bean is doing in an Enterprise application can be written in Struts Action class

No, it can't at least not easily. To replicate all the container provider services (and applicaiton management tools available in EJB containers) yourself is non-trivial. I think you may have a slightly oversimplified understanding of what functionality EJBs provide.
 
Abubacker Siddik
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think i understand EJB has something to be worth considering...but i have a requirement to build a web application. Now In which scenario i should go for EJB and in which i should not..Because i can integrate Struts-hibernate-jsp/servlet and Database to complete my project..

Give me an exact example or scenario in which i must use EJB..
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, why are you condisering EJB? What container provided services are you plannign to use?
 
Abubacker Siddik
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thats what i am asking you guys..for which container services i should go for EJB? Or can I replace EJB?

For an Enterprise application, i have business tier.. I understand i should use EJB for the business tier..isnt it??? my question is that can i use other technologies(i dont know other technologies exist) to replace EJB?
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, your business logic can go wherever it makes architectural sense for it to go. If you are writing a simple web application EJB may very well be a considerable overhead. There are a lot of questions you can ask yourself which might point you in the direction of EJBs (or a simmilar technology); these are far to many to list completely here which is why I'm asking you what you think you might need. Since you use EJB for the container provided services EJBs give you access to, you need to ask which of these services will I be using? If the answer is "none" then you probably don't need EJBs (or Spring for that matter). If the answer is "I don't know" then you probably need to take a little time to review your overall architecture and have a think about it.
 
Abubacker Siddik
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
fine paul. I think i should say "i have to give it a think.' Moreover please give some other technology options which i might use in place of EJBs..
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well you have plain old java objects calling third party APIs that replace container provided services, or Spring (which is kind of the same thing). Again though neither of these routes are applicable if you don't need the container provided services in the first place.
 
Abubacker Siddik
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Then can i conclude from your discussion that EJB is mere provider of container services? Because i thought it is that way it seems...So when i need container services for my application, i can use EJBs..??


Thanks for your so-far-clarification..
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic