To EJB or not to EJB
tomyoung67 Feb 24, 2003 2:13 PMHi all:
I’ve been using TomCat, JSP, JavaBeans to talk to database servers via JDBC/ODBC and I feel I can do any Web/database related work with the tools I have, such as generating dynamic Web pages and storing/retrieving data from different database servers such as Oracle and SQL Server. I didn’t use any J2EE/EJB.
Because it seems EJB is a hot topic and lots of people are using it, I studied a little about it. So far, I haven’t found any advantage of using it. In fact, I feel several disadvantages of using it:
1) You would have to use a heavy weight EJB application server such WebLogic or WebSphere, which are kind of more difficult to learn and certainly more expensive to buy than using just a light weight servlet/JSP engine like TomCat.
2) When you use EJB, you would have to follow the strict rules of programming, such as defining the interfaces for each EJB. With just using JavaBean, you don’t have this problem.
3) Each Entity Bean corresponds to a database table. When the database table is changed, such as adding/renaming/deleting columns, the corresponding EJB file would also have to be changed. Compared with using just a JavaBean to do the database work, the changes involved will be minimal - usually, just changing the SQL statements querying the table.
4) Deploying the EJB is certainly much more complicated than deploying the JSP/JavaBean files in TomCat. With the former, you have to go through all the steps creating the .jar, .war, .ear files and define the jndi names etc., while with the latter all you need to do is just drop the files into the correct folder.
5) With using the EJB, the .ear file created for one application server often doesn’t work with another application server (I tried to put the .ear file which works for one EJB application server onto another application server and it didn’t work. Other people had similar experiences like mine). I ended up having to re-create the .ear files for the new application server which cost me quite a bit of time. However, with using just a servlet engine, I would think you can just move the source code to the correct folders if you change the engine and it will work.
6) I heard people say “EJB provides almost transparent scalability”. What does “scalability” mean exactly? Does it mean when the number of users of my application written using only JSP/JavaBean (without EJB) increases to a certain point, my application will run into the “scalability” trouble? If so, what kind of trouble is called “scalability” exactly?
7) Another advantage of EJB I heard was “transaction management”. Why do I need that? I can use JSP/JavaBean to issue all kinds of SQL statements and commit or rollback any transaction as needed. Why do I need EJB’s “transaction management”?
8) Another advantage of EJB I heard was “security”. My application currently uses username and passwords to authenticate users. If the user provides the correct username and password, then he/she can access the Web page. If not, then he/she cannot access the Web page. Is this kind of authentication inferior to the one EJB would provide?
Having said above, my key questions are:
Is there anything EJB can do but using just JSP/JavaBean cannot? For example, you can call the methods defined in the remote interface of a session bean to do your work such as issuing all kinds of SQL queries/updates after you have instantiated that session bean in a Web page, but I can also call the same methods defined in a JavaBean and do exactly the same thing. What is the difference between the two other than the fact that the former can be said “I am using EJB”? But with the former you do have to use a complicated heavy weight EJB Application Server. What are the advantages of using EJB compared with just using just JSP/JavaBean? Why are people so enthusiastic about using EJB? So far, I feel I can do anything without using EJB and I do feel using EJB just complicates the work unnecessarily, especially with using Entity Beans. I’m sorry if my questions sound naive because my experience with using EJB is very limited. Thank you all for your answers to my questions in advance!
Tom