When is it appropriate(rather, the only choice) to use a BMP Entity Bean as against a CMP Entity Bean? We have a table which also has a child table. For each row in the parent table, there will be one or more rows in the child table. If I want to develop an entity Bean for the parent table, can I use a CMP Bean? Is it possible to depict this relation correctly, using the Deployment Descriptors, according to EJB1.1? Please help. Thanks!
If you have more than one table involved you need to use BMP or if your database supports updateable views you could use CMP and create a view to reference.
It is a common misconception to think that CMP is limited to only one-table database schemas. Yes, with CMP you can map your bean to only one database table/view, but doesn't necessarily mean that you are limited to one-table schemas.
svoropay, The Java Ranch has thousands of visitors every week, many with surprisingly similar names. To avoid confusion we have a naming convention, described at http://www.javaranch.com/name.jsp . We require names to have at least two words, separated by a space, and strongly recommend that you use your full real name. Please choose a new name which meets the requirements. Thanks, Matt
It is hard to come up with any good online resource on this topic, but a very good printed resource would be "Enterprise Java Beans 2d Ed." by Richard Monson-Haefel. A whole section called "Entity beans relationships" in chapter 9 is devoted to this topic, where the author suggests a few possible ways of dealing with relationships between EJBs. Regards, Sergei
Sergie, I've read that topic from Richard's book. He does specify the CMP way of dealing with relationships between EJBs, but he also states that UNLESS your App.Server supports Object-to-Relational data mapping, the only way of dealing with many-to-one relationships is to use BMP. I just wanted to make sure that this issue is cleared out, and that I've understood that book correctly. Your comments are welcome. Thanks!
It looks like people have mixed opinions on this topic. Some say it is ok to mimic one-to-many relationships with CMP ejbs through bean references, some say that it's too costly and inefficient in terms of performance and alternative solutions (o/r mapping) should be used. I'm a supporter of the former approach considering the benefits CMP provides even if I have to sacrifice some performance. For small to medium complexity database schemas involving one-to-many relationships, mimicking the relationships between beans through references is very easy -- just extend the concept provided in the book to collections of objects. Here is a little example on one-to-many relationships between CMP ejbs from the Borland web site: http://www.borland.com/techpubs/books/appserver/appserver40/examples/ejb/pigs/README.html.
Hi "sarah00", The Java Ranch has thousands of visitors every week, many with surprisingly similar names. To avoid confusion we have a naming convention, described at http://www.javaranch.com/name.jsp . We require names to have at least two words, separated by a space, and strongly recommend that you use your full real name. Please choose a new name which meets the requirements. Thanks.