Discussions

EJB design: Number of tables; BMP or CMP for entity beans?

  1. If you have 2 beans that relate to each other and both must be updated at the same time, is have two CMP beans linked together with a vendor specific tool ok, or would it be better to use a BMP bean to update both tables in one go?

    Is there an upper limit on how many CMP beans should be related. Is it 1 etc. Should CMP be used only for non-relating tables for updates?

    Cheers.
  2. When you say the same time, do you mean simultaneous update? Or do you mean concurrently as in table 1 is updated and within the same transaction table 2 is updated .. these are two different scenarios and would require to different solutions.

    rich
  3. I assume here that you have two beans which map to two tables with a possible join. Typically, I think these cases cannot be handled by CMP since you cannot specify more than one table for the bean unless I am missing something. BMP's are preferred if the dependency is pretty simple otherwise use a OR mapping tool like top link if you have number of foreign key specifications in the RDB.
  4. 1 table per bean, with a join on a foreign key and I want to update both of them in one update. There is not more than 1 table per bean. So I can use CMP, but is BMP better for this sort of situation?

    Should I only use CMP when I have 1 table and no joins off that table. When I have foreign key mappings, use BMP as a rule?

    Cheers.
  5. thats right. The AS may optimize queries, do caching, batch updates which generally u would have to do by hand. So it would make sense to use CMP for 1 table per bean and use BMP only if you have joins. Besides BMP is pretty bad for being scattered all over the place if you are going to make every bean persist itself. But in any case never use a mix of BMP, CMP weblogic or for that matter any AS can get confused and you can get data inconsistensies because all AS's use deferred updates and BMP's update generally real time. All this can be part of your design nevertheless
  6. I take it you mean don't mix BMP and CMP in the same tranasaction, but you can use both BMP and CMP beans in an application. Yeah?
  7. No No I mean dont use BMP and CMP to update some common table. There may be a user bean updating user address table and may be some other bean updating the same table. Now if you mix the two, this can lead to inconsistencies as the AS can potentially cache or deferred updates. And obviously this includes updates within the same transaction as well. To summarize as long as the tables are disjoint and there is no overlaps you can use both but if you have overlaps you are better off using one of the methods.