Search code examples
jakarta-eeejbpojo

Choice of a class inside an EJB container


I have some basic questions on EJBs (in the light of EE 7).

Here is a class hierarchy:

public class Class1 {};
public class Class2 extends Class1 {};
public class Class3 extends Class1 {};
public class Class4 extends Class3 {};

I would like to make an EJB out of Class4. So,

  • Is it necessary that I turn Class1 - the super class - into an EJB or can I simply turn Class4 into one?
  • Does it matter if Class1 is abstract or concrete?
  • If I do turn Class1 into an EJB, do all its sub-classes become EJBs?
  • Is every class in this hierarchy a POJO?
  • Regardless of how many EJB's I make, will there always be one EJB container?
  • If there are multiple EJB's running inside the container, is it necessary for them to use a JMS implementation for their communication, or CDI?

Solution

    1. You can simply turn Class4 into an EJB. Just annotate it with @Stateless to make a stateless EJB, and with @LocalBean if you want to expose its methods without declaring an interface.

    2. It does not matter if Class1 is absract or concrete.

    3. If you turn Class1 into an EJB, it will have no impact on its inherited classes. But Class1 must not be abstract in this case.

    4. Err...yes...?

    5. Yes

    6. You may use JMS in the case where some EJBs are Message Driven Beans. But if your EJBs are SLSB of SFSB, they will communicate through plain java calls on the same container, or using RMI if they are not on the same container. CDI can be used to obtain instances of EJBs (@Inject), because EJBs are CDI beans. But you can also use basic DI to to that (@EJB)