Using relationships in your code

In your bean code, you use your virtual relationship fields just as you would any other getter and setter. The only difference between using a real field (i.e. an instance variable declared in your class) and a virtual field is that you can access your virtual fields only by calling the abstract getters and setters (which the Container implements at deploy-time).

The only new restriction is that a relationship field can be only a local component interface type! You can’t have a CMR relationship field that uses a bean’s Remote interface!

You can use your virtual relationship fields just as you would any other virtual field... by calling the abstract getters that YOU defined, but which the Container implements.

The type of a relationship field MUST be the local component interface of the entity!

A CMR field will ALWAYS be a local component interface type.

Virtual field in the bean class

image with no caption

Exposed business method in the bean class

image with no caption

Get Head First EJB now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.