1) ID - EJ001 When should you use CMP? (A) When performance is essential and you are storing standard data types. (B) When performance is not essential and you are storing standard data types. (C) When performance is essential and you are storing complex data types. (D) When performance is not essential and you are storing complex data types. Anwer is b but I guess CMP has a better performance then BMP, rite?
Hello, I think BMP persistence will out perform CMP because of the SQL queries used. When using BMP you will write your own queries so they will always be the best (in theory). However with CMP you are asking the app server to generate the SQL it thinks will be the best for the job, this may not always be the case. There is something in the SCEA Guide book about this; it says eventually when the generation of the SQL improves CMP will be as good as BMP. Ian
Actually in most cases CMP will outperform BMP hands down. The Container can highly optimize the SQL queries. For example, in BMP fetching an Entity requires two database reads: first to get the PK in ejbFindByPrimaryKey() and second to fetch the entire record in ejbLoad(). CMP optimizes this to only one query to retrieve the entire Entity at once. The difference is even greater with an Entity Finder method that returns a Collection of Entity. In BMP it requires N + 1 reads against the database: 1 read to get the list of PKs and N reads to load each Entity from the database. In CMP this is usually optimized to one big read, much better performance. Most CMP Containers also keep track of changes to the Entity and ONLY write those fields that have changed back to the database in ejbStore(). This could be accomplished by a BMP developer but it is going to take a bit of work to do at the individual field level and the cost of maintenance is now higher. Bottomline: in the majority of cases CMP will outperform BMP. The big question is will CMP be flexible enough for your projects' needs. This needs to be determined on a project by project basis.
And with CMP, in order to better map to a relational database, you would need to use a tool like TopLink, to map your relationships. With BMP you write your own SQL, so you know your relationships and can write code to "Save data to multiple tables from one Entity Bean. At least I think I am write. Please correct me if I am wrong. Still studying. Mark