Finder methods: CMP vs BMP


EJB design: Finder methods: CMP vs BMP

  1. Finder methods: CMP vs BMP (3 messages)

    Hi forum,
    I would like to know what strategies people use in real life to design their entity beans, when use CMPs and when BMPs. Each approarch has its own benefits and drawbacks.
    This is what I found out during my experience with EJB:
        - easy to develop;
        - better perfomance.
        - less flexible then BMPs;
        - some of the queries cannot be performed with pure CMP, so sometimes it is necessary to add a data access object ( java class ) that uses JDBC to directly communicate with database ( to retreive the number of records etc. ).
        - not all queries can be coded with CMP finder methods ( consider example: I need to extract 20 records, starting with 500 out of 3000 records in a table. Using Collection would be extremely expensive ).
        - full control over data flow. you can do anything JDBC is capable of.
        - huge perfomance degradation when retrieving a collection of BMPs - the problem of n+1 call.
    My conclusion is: everyting is fine with the creation, updating and deleting the entities. The problem arises with finder methods: You are either to slow with BMPs or fast with CMPs but with limited functionality. Another idea is to use CMPs to create/update/delete entities, but use JDBC and retreive collections values value objects for finders, something like:
    public class EntityValue {
        public int id;
        public String data;
    The problem here is that we lose encapsulation... How do you handle this situation?
    Any suggestions are very much appreciated.

    Threaded Messages (3)

  2. Finder methods: CMP vs BMP[ Go to top ]

    Are you referring to the Fat Key pattern?...

    I generally model searches (those that return extremely large amounts of data) as EntityBeans...but this is only when this data needs to be updating and not viewed.... So I have an entity bean modelling, not an entity as in a table-row, but as a relationship (which is again an entity)... the primarykey is the derived from the relationship parameters... Hence for most places I donot need hefty finders...which are are a bad idea (even sun admits)... Session beans can also be used... the problem... you'll probably invalidate the whole db-cache used by the appserver... performace issue.
  3. Finder methods: CMP vs BMP[ Go to top ]

    I use only CMP entity beans. I feel that they
    are faster both development and performance -wise.
    They are also easier to maintain.

    When retrieving large amounts of read-only data I use a specially designed Util-bean, which is a statless session bean.

    Sten Karlson

  4. Finder methods: CMP vs BMP[ Go to top ]


    I completely agree - CMPs are way to go. I think that the more tasks you delegate to CMPs the less problems with debugging and maintainance you have.

    Using an additional bean adds complexity to the application development/maintainance: if you change your CMP, you have to make additional changes to the utility classes... Sometimes, however, you cannot avoid it (count query is an example).

    I have a specific issue: i need to do page-by-page iteration (something like a search engine). For example, i need to show 50 entries out of 2000 starting with 500. But my database doesn't support cursors on the server side. On the EJB side, if you use CMP you don't have access to the client cursor.

    Is it possible to implement page-by-page iteration using plain CMPs?

    Any help is very much appreciated.