As a rule, it is a bad idea to execute any logic in the constructor (not only on the EJB playground). Use @PostConstruct
:
@PostConstruct public init(){ listOfRoles = roleFacade.getListOfRoles(); listChoosenRoles = new ArrayList(); listOfDualRoles = new DualListModel<Roles>(listOfRoles, listChoosenRoles); }
Using this annotation, the container first creates an instance of the EJB object, the JVM starts the (empty) constructor, the container enters dependencies through reflection, and when everything is ready, it will call all methods annotated with @PostConstruct
in the unspecified order. EJB is now ready to serve requests.
I think some containers / new EJB specifications allow constructor injection, but I never used it.
source share