Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6647497
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:32:42+00:00 2026-05-26T00:32:42+00:00

I have a Facade that has a persistence unit. And I need the Facade

  • 0

I have a Facade that has a persistence unit. And I need the Facade and it’s dependencies initialized before the RoleController Conconstructor runs, is it possible in EJB 3.1 to do that ?

In Spring you simple add some parameters (preConstruction=”true”) to the @configurable and it’s done.

But in EJB I cannot find a way to do that I always get a NullPointer…

@FacesConverter("rolesConverter")
@Named("roleController")
@SessionScoped
@TransactionManagement(TransactionManagementType.CONTAINER)
public class RoleController implements Serializable, Converter{

    private List<Roles> listOfRoles; 
    private List<Roles> listChoosenRoles;
    private DualListModel<Roles> listOfDualRoles;
    @EJB
    private RoleFacade roleFacade;

    public RoleController(){
        listOfRoles = roleFacade.getListOfRoles();
        listChoosenRoles = new ArrayList();
        listOfDualRoles = new DualListModel<Roles>(listOfRoles, listChoosenRoles);
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T00:32:42+00:00Added an answer on May 26, 2026 at 12:32 am

    It is generally a bad idea to perform any logic in the constructor (not only on EJB playground). Use @PostConstruct instead:

    @PostConstruct
    public init(){
        listOfRoles = roleFacade.getListOfRoles();
        listChoosenRoles = new ArrayList();
        listOfDualRoles = new DualListModel<Roles>(listOfRoles, listChoosenRoles);
    }
    

    With this annotation the container will first instantiate an EJB object, JVM runs an (empty) constructor, container via reflection injects dependencies and when everything is ready calls all methods annotated with @PostConstruct in unspecified order. Now the EJB is ready to serve requests.

    I think some containers/newer EJB spec allows constructor injection, but I have never used it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Java enterprise application that provides a web service, has a domain
I have a Java web application that uses the SLF4J logging facade. To date,
I have a facade class that my controller class calls out to and in
I have an xml file in a WCF application that describes dependencies. It is
I am working on an enterprise project that has an EJB module and a
In my service facade layer, I have a service class with a method/operation that
I have an application which has some classes that handle some specific functions, have
Have just started using Visual Studio Professional's built-in unit testing features, which as I
Folks, Apologies if this has been covered in another thread, but I have searched
Since I asked How has to be written the signature in facade pattern? question,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.