title: ejb references passed in helper class or create ejb instead
body: <p>I was wondering which one of the two solutions hereunder is the best practice?</p>
  
  <p>Problem : I have a stateless session bean VehicleBean, I implemented a method with business logic and persistence of a Car with its wheels , their tires, etc.</p>
  
  <pre><code>@Stateless
  class VehicleBean{
     @PersistenceContext
     private EntityManager em;
  
     @EJB
     Inspector inspectorBean;
  
     @EJB
     DocumentBean documentBean;
  
     public void persistCar(){
        Car car = new Car();
        car.setMake("Ford");
        em.persist(car);
        documentBean.persistDocument(new Document(car));
        for (int i = 0; i &lt; 4; i++){
           createWheel(car);
        }
     private void createWheel(Car car){
        // some business logic
        inspectorBean.inspect();
        Wheel wheel = new Wheel();
        wheel.setCar(car);
        em.persist(wheel);
        ...
     }
     ...
  }
  </code></pre>
  
  <p>I have different private methods that are called after each other (1) create car, 2) create wheels, etc) and I would like to regroup all these methods in one helper class.</p>
  
  <p>Solutions:</p>
  
  <p>1) Make use of a helper class CarBuilder which contains all the private methods from my VehicleBean. As I can't use ejb injection, I want to pass it by reference to the constructor as following :</p>
  
  <pre><code>public void persistCar(){
     new CarBuilder(this, document, inspectorBean);
  }
  
  class CarBuilder{
     private VehiculeBean vehiculeBean;
     ...
     CarBuilder(VehiculeBean,....){
        this.vehiculeBean = vehiculeBean;
     }
  }
  </code></pre>
  
  <p>2) create CarBuilder as a stateless session bean and inject the bean in the VehiculeBean.</p>
  
  <p>Do you see any advantage using the 2)? So having a lot of different beans like CarBuilder, MotorcyleBuilder, etc managed by the container.</p>