Discussions

EJB design: Design Issue-Entity vs Session for dbms

  1. Design Issue-Entity vs Session for dbms (6 messages)

    I need to know while designing an application how to decide about using entity and session beans for database interaction.
    for example there is a form for entering customer details(name,address and phone).Once the user enter the details they have to be stored in the database.Now my problem is whether i should develop entity or session bean for storing details in database.In some books enity bean is used for dbms storage while in some cases session bean is used.
    For storing details in dbms which bean do u vote-session or entity and why?
    Please show some light on resolving this issue in EJBs.
    Thanks
    Sweety
  2. Entity Beans used for the database purpose. From session bean you can also access database but it won't be container managed and you can call entity bean from session bean by declaring instances.
  3. You have two parts to your question: (a) Customer information and (b) Business process of updating customer information

    (a) This is an entity bean because all database objects are entity beans.

    (b) This is the session bean. You wrap your entity bean (a) with session bean (b).

  4. Session beans are not sharable between multiple clients while entity beans are sharable.If we use session bean for calling updateCustomer method which will call entity bean in turn,then does that mean that only one client can call update method at a time then how will it resolve the requests by multiple clients who are updating the data and calling update method at the same time.

  5. As mentioned by Adi,
       You use Entity bean for Database Persistance and Session Beans for the Logic over it.
       In otherwords any kind of formating or calculations are done in the session bean and then the Entity Bean can be used for making the data persistant.

      You can also not use the Entity Bean at all and Handle the Database storage and Manipulation in your session bean.

      When it is done it still make it available to other clients accessing the Data. If you are using Entiy Beans and CMP then the data is automatically persistant for you.

      But in the second case when you use Session Bean which is like BMP the data updated(Modified/Added) by one Client is available to another client when requested by the Client.

      A seperate session bean is created by each clients request and if the changes are available at the time of query in the database they will be made available .

     So for your particular query about the UPDATE, if more than one Client does it then it happens so many times. and it is reflected in the DB as soon as the Trasaction is over.

    Good luck..


  6. I should apologize for not reading it through.

    If we use Session Bean to call entiy bean ..

    If more than one client is requesting at the same time then the thread management is done by tht Container and all the requests are queued and changes are made one after the other.
  7. Also, if your system encounters a crash/shutdown, entity beans guarantee persistence whereas session beans do not. This would come into question if you have deferred updates.