Discussions

EJB design: When to use Entity Bean and DAO?

  1. When to use Entity Bean and DAO? (1 messages)

    Currently I am developing a application using BMP.

    I have a question here. When should I use Session EJB to call Entity EJB ? When should I use Session EJB to call DAO directly?

    I set a few guideline on the question above.

    I will use Session EJB to call Entity EJB when
    1. Insert, Update, Remove a record
    2. Select a record from a table

    I will use Session EJB to call DAO when
    1. Insert, Update, Remove >1 records
    2. Select >1 records from a table
    3. Select a record from >1 table

    I follow this guideline because bulk access through DAO is faster than going through Entity EJB.

    But I was wondering whether this is a good design? Or is there any other better way?
    In fact, it come to a question that why we need Entity EJB? Because I can access everything through DAO !

    Please advice
    Thank You

    Cheers
    Ray
  2. When to use Entity Bean and DAO?[ Go to top ]

    You would use entity beans if:

    * You have stringent transactional requirements that must be enforced for entity bean methods separately (i.e., transactions cannot be controlled at the facade level)
    * The entity must be a reusable component
    * You don't mind about the N+1 database call problem with BMP
    * You'd like to be an OO/component purist
    * You want to use your application server's timed auto-reloading (or similar) functionality

    But, in general, BMP beans are a waste of time. You're much better off with either CMP or a decent O/R framework.

    Regards,
    Pietari Laurila