I have a CMP entity bean. This bean (and its underlying database table) are closely tied to several other entity
beans. What I'd like to do (while still keeping the bean a CMP) is add a finder method that does a more complicated join query in order to create an instance of the bean. Is there a way to do this?
With EJB 1.x, you are not going to be able to do this. CMP in 1.0 and 1.1 is too limited and won't let you go across tables. However, you might want to check the 2.0 spec which is now in final release. A number of existing containers will support it. If you are on an 1.x server, I am afraid you are stuck with BMP.
Depending on your situation, there may be strategy that would work. If you have a foreign key for the other beans in your main bean, you may be able to keep a copy of the other beans' home interfaces and use their finder methods. From a bean business method you would return OtherbeanHome.findByPrimaryKey(foreign_key_value). This, in essense, causes the parent bean to lazily instantiate the child beans. It won't help you particularly from a performance point of view, since you can't do a real database-join, but it may help your design.
Dig deeper on Java Web Services
Have a question for an expert?
Please add a title for your question
Get answers from a TechTarget expert on whatever's puzzling you.