I am new to EJB and I have small doubt abot it;s usage, Requesting to clarify it:
- Normally in projects, people are using stateless session bean to access database(for select, update and delete) and they leave data concurrency handling at database levels. Now,(a) I am unable to understand what kind of benefit they are getting by useing stateless session bean? (b) Instead of using Stateless Session bean If I will use simple java class then which kind of problems I may get into?
Hope you understand my questions? Looking for clarification...
Basically Entity Beans are used to connect to the Database (it is not a good practice to connect to a database thru a Statless or Stateful Session bean) thru a JNDI Name.... JNDI Naming makes it easier to connect in an enterprise becuase it abstracts the datasource classname etc from the developer,
The main advantage of using EJBs over Simple beans is that J2EE has a moto of develop once deploy many, if there is a slight change in business logic etc, the developer can change the business requirements and redeploy the bean and the client wouldnt have a whiff about it.
Other than that there are many features in EJBs, for example the Container Managed Persistance in Entity Beans enable you to find, create, delete, update records in your database without going thru the hinderance of writing SQL Scripts which increases database integrity, another feature of Entity Beans is Container Managed Relationships which maintains schema integrity....
These are just some benefits that I guess are benefitial in a large environment over legacy systems when we compare EJBs and normal Java classes.
Ok I understood where you are struggling. Your mind is not ready to acccept that if a transaction is done by a simple java class , then why to write the ejb & all stuff........? See when you write a simple class, the writer is resposible for taking care of the DataBase commit/rollback, checking the rights of user , (authorization & authetication) and many more. All in one developer gets stucked to lot of other common functions as Transaction, Security etc other than core business logic. To remove this disadvantage EJB's are introduced. EJB's asks you to care only about business logic & dont care about all other stuff. At start this will give you a boring feel.....but when your project becomes more complex, you want to get free from all other stuff as commit...rollback etc. Remember: decision to go with EJB or not is througly depends on need of project. If you want to develop a simple "Hello world" web site , in such condition obviously you need not to go with EJB.
Hey, sticks and stones baby. And maybe a wee mention of my stuff:
a bit of art, as a gift, that will fit in a stocking