Ask the Expert

Adding a finder method

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?

    Requires Free Membership to View

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.

This was first published in October 2001

There are Comments. Add yours.

TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to: