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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T18:35:57+00:00 2026-05-30T18:35:57+00:00

I am currently working on an application utilizing Guice / JPA / Hibernate to

  • 0

I am currently working on an application utilizing Guice / JPA / Hibernate to get info from my database.

I have read the Guice docs on working with JPA and EntityManagars here: http://code.google.com/p/google-guice/wiki/JPA,

But I am having trouble understanding when I should make my DAO Implementations Singletons.

I have read this question on S/O regarding Spring’s use of DAO’s where it says:

Instantiating a DAO for every request would be crazy.

Does that carry over for DI containers other than Spring? If I am injecting a DAO Provider into my Servlet and calling when needed, should the DAO Service Implementation be a Singleton?

Here is a basic outline of one of my DAO’s:

public DAOImpl implements DAOService { <-- SHOULD THIS BE ANNOTATED @Singleton?

    @Inject
    private EntityManager em;
    // OR 
    // @Inject 
    // private Provider<EntityManager> emProvider - If it's a singleton.

    @Inject
    DAOImpl(OtherServices os) {
        this.otherServices = os;
    }

    @Transactional
    public MyPersistedObject getPersistedObject(long id) {
        MyPersistedObject mpo = em.find(MyPersistedObject.class, id);
        return mpo;
    }
}

And how it’s called:

   @Singleton
   public MyServlet(HttpRequest req, HttpRequest res) 
           extends ServletInterfaceOfTheDay {

       private final daoService; // If Singleton
       // OR
       // private final Provider<DAOService>; If Instanced DAO

       @Inject
       MyServlet(DAOService dao) {
           this.daoService = dao;
       }

       // Gather Information from request here...

       MyPersistedObject mpo = daoService.getPersistedObject(requestIdInfo);
       // OR daoService.get().getPersistedObject(requestIdInfo);

       // Process Response Info here....

   }

Thanks for the help.

  • 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-30T18:35:58+00:00Added an answer on May 30, 2026 at 6:35 pm

    No, since EntityManager is absolutely not Thread-safe. You need to use providers.

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

Sidebar

Related Questions

I am currently working on an application for a client, and they have made
I'm currently working on an application where I need to load data from an
I am currently working on an application that pulls Google Map locations from an
I am currently working on rails3 application that uses jQuery. I have a javascript
I am currently working in iPhone application in which I have used wikitude api.
I'm currently working on an application, i have this button which link to some
Currently working on a bespoke ecommerce application using Codeigniter. I have a products table
Am currently working on an application that requires users to submit posts and comments
I'm currently working on an application with a frontend written in Adobe Flex 3.
We are currently working on an application that will use a WCF service. The

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.