Search code examples
javajakarta-eeejbfacade

EJB Façade calling methods in another EJB


I am trying to invoke methods of an EJB Facade from another but I am facing some errors then I ask your help to do this in correct way. I will post the current code to try to explain.

The JSF Bean front end object starts the sequence of calls:

@RequestScoped
public class FrontEndBean {

    @EJB
    private SomeFacade someFacade;

    public String submit() {
        MyEntityObject myobj = new MyEntityObject();
        myobj.setStringProperty("somestring");
        someFacade.businessMethodOnSomeFacade(myobj);
    }

}

The first Façade source looks like this:

@Stateless
public class SomeFacade {

    @EJB
    private AnotherFacade anotherFacade;

    public void businessMethodOnSomeFacade(MyEntityObject obj) {
        if (obj.getStringProperty() != null) {
            anotherFacade.businessMethodOnAnotherFacade(obj);
        }
    }

}

And the Another Façade:

@Stateless
public class AnotherFacade {

    public void businessMethodOnAnotherFacade(MyEntityObject obj) {
        if (obj.getStringProperty().equals("somestring")) { // null pointer exception

        }
    }

}

Is it correct? Can I invoke an EJB façade from another using @EJB? If not, What is the correct way to do this?


Solution

  • Yes everything is correct. You can inject whatever EJBs you like.