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 7549183
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T09:53:15+00:00 2026-05-30T09:53:15+00:00

I observed some strange behavior regarding injecting EntityManager. Following is stripped down version of

  • 0

I observed some strange behavior regarding injecting EntityManager.

Following is stripped down version of working code:

Bean.java

@RequestScoped
@Named
public class Bean {

    @Inject
    private Service service; // +getter

    // few variables + getters/setters

    public String getMessage() {
        return getService().message();
    }

}

Service.java

@Stateless
@LocalBean
public class Service {

    @PersistenceContext
    private EntityManager entityManager; // +getter

    public String message() {
        return "[" + getEntityManager() + "]";
    }

}

cdi.xhtml

<h:body>
    <h:outputText value="#{bean.message}" />
</h:body>

But I needed to do some processing, while creating Service. So added following producer method, in factory class.

    @Produces
    @QService
    public Service createService() {
        Service service;

        service = new Service();
        // Some processing
        return service;
    }

and added same qualifier QService at injection point in class Bean.

    @Inject
    @QService
    private Service service; // +getter

Now, EntityManager is NOT injected in class Service, it remains null.

I’m not able to understand this behavior. Can someone explain this?

  • 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-30T09:53:16+00:00Added an answer on May 30, 2026 at 9:53 am

    I think the problem is this line:

    service = new Service();
    

    Since Service is an EJB it’s lifecycle is managed by the container. You are allowed to call new but I guess you will not get an EJB but a pure java class.

    Try to inject the Service EJB instead of creating a new instance.

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

Sidebar

Related Questions

I'm observing some strange behavior with a local variable within a nested for loop
I have run into some strange behavior. I am not sure if this should
I observed a relative strange behavior when I use floating images in a document.
I observed some unexpected behavior with TTLauncherView from Three20. After creating a standard view
What are some of the things you've observed in ColdFusion 9 with CF-ORM (Hibernate)
What best practices should be observed when implementing HDL code? What are the commonalities
With a third party API I observed the following. Instead of using, public static
I have a view (actually, it's a table valued function, but the observed behavior
I often find this strange CDATA tag in XML files: <![CDATA[some stuff]]> I have
I observed some inconsistency between two compilers (g++ 4.5, VS2010 RC) in the way

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.