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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:09:56+00:00 2026-05-28T05:09:56+00:00

I have a doubt a long time and never find the answer, so I

  • 0

I have a doubt a long time and never find the answer, so I appreciate any king of help or explanation… maybe it´s is just a conceptual mistake…

I have an environment where I use CMT and Hibernate. I can inject the EntityManager as a resource on my EJB without any problem. But I couldn´t make it inject direct in my DAOs, since I instantiate it with a traditional factory pattern….

But my question is: I need to use the EntityManager, but don´t want to pass it all the way down through my layers! Must have another way and I´m probably not seeing the solution…

Can I do some king of context lookup for this EntityManager? Or any other more elegant solution?

I made my own solution, but its kind of crap lol… don´t worth a discution…

Thanks for any help and sorry for any english mistake, it´s not my native language.

  • 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-28T05:09:57+00:00Added an answer on May 28, 2026 at 5:09 am

    Even following the JBNizet sugestion, I still curious to know how to get the EntityManager and I found this answer in how to lookup for the EntityManager on J2EE/EJB environment.

    First, you need to put a @PersistentContext on the class scope of your EJB to set a def for later lookup and define the “name” attribute. Like:

    @PersistenceContext(
    name="myEntityManagerJNDIName",
    unitName=InventoryManagement  // defined in a persistence.xml file
    )
    @Stateless
    public class InventoryManagerBean implements InventoryManager { ... }
    

    Then you can lookup for your EntityManager with a code like this:

    ...
    // obtain the initial JNDI context
    Context initCtx = new InitialContext();
    // perform JNDI lookup to obtain container-managed entity manager
    javax.persistence.EntityManager entityManager = (javax.persistence.EntityManager) 
       initCtx.lookup("java:comp/env/myEntityManagerJNDIName");
    ...
    

    That is the way I found to get the EntityManager without injections.

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

Sidebar

Related Questions

I have this doubt from long time, When ever I write the class using
I have this doubt for a long time... hope anyone can enlight me. Suppose
I have had this doubt for a long time . I download a project
I have a doubt: - Is there any standard/convention that when should I use
I have been having this debate with my boss for a long time, now
Hai guys, I had this doubt for a long time now. Now being a
I have just finished building a heavyweight long sales page, with a lot of
I am working in android application.I have one doubt How long it takes to
Possible Duplicate: What is the difference between const and readonly? i have doubt in
I have a doubt about orkut's new URL Writing method. Earlier the home page

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.