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

  • SEARCH
  • Home
  • 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 8787315
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T21:51:43+00:00 2026-06-13T21:51:43+00:00

I know that injection using the @EJB annotation is only possible in an EJB

  • 0

I know that injection using the @EJB annotation is only possible in an EJB class, a servlet, or a JSF managed bean, but in the same time I need to have an instance of a some injected business interface in a POJO class, so I thought of doing the following:

in my JSF managed bean

@EJB BusinessInterfaceLocal businessInterface;

private void someMethod(){
    PojoInterface pojo = new PojoClass(this.businessInterface);
}

and in my POJO class I have this constructor

BusinessInterfaceLocal businessInterface;    

public PojoClass(BusinessInterfaceLocal businessInterface){
   this.businessInterface = businessInterface;

   //The following throws a Null Pointer Exception
   this.businessInterface.someMethodCall();
}

Shouldn’t the above work correctly? but it doesn’t, the businessInterface object at the PojoClass is evaluated to null, and thus throwing a null pointer exception.

I was hoping if anyone could point me out, on what I’m doing wrong.

Thanks in advance.

  • 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-06-13T21:51:44+00:00Added an answer on June 13, 2026 at 9:51 pm

    verification

    Is it possible you create the PojoClass before the EJB gets injected. By that I mean, where do you invoke “someMethod”? Is it in the constructor of the managed bean? A variable simply does not lose its referenced value.

    You said you could see the BusinessInterfaceLocalbean isn’t null in the Managed bean, can you verify you create the Pojo after that check?

    Alternative solutions:

    solution 1
    You can use the POJO as a stateless bean, I don’t see any problems in doing that, unless of course you are trying to use the POJO outside of your EE container, which is, by the looks of it not the case.

    Making the POJO stateless would make you able to inject the EJB.

    solution 2
    OR a JNDI lookup, implemented as followed:

    @Stateless(name="myEJB")
    public class MyEJB {
    
      public void ejbMethod() {
      // business logic
      }
    
    }
    
    public class TestEJB {
    
      public static void main() {
      MyEJB ejbRef = (MyEJB) new InitialContext().lookup("java:comp/env/myEJB");
      ejbRef.ejbMethod();
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know using prepared statements helps to avoid sql-injection. My problem is, that a
Well, I know that correct escaping will help to prevent SQL injection. But I
I know that Phonegap has an event for back button, but it's only available
I know that this sort of question has been asked here before, but still
I know that Java have its own garbage collection, but sometimes I want to
I know that immutable objects always have the same state, the state in which
i want to know that is there any chance of SQL injection via selectbox
I know that Spring doesn't supports Interface injection and I've read that many a
Can I safely prevent SQL Injection using PostgreSQL's Dollar-Quoted String Constants? I know the
I have a RESTful service which injects an EJB(3.0) using the @EJB annotation. This

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.