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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T05:20:12+00:00 2026-05-14T05:20:12+00:00

I am learning JPA and have one question: In which situations we need more

  • 0

I am learning JPA and have one question:

In which situations we need more than one EntityManager in our application?

The two situations that I am aware of are as follows:

  • When our application is a multi-threaded application and more than one thread needs JPA transaction because EntityManager is not thread-safe and we need one EntityManager per thread.

  • When any of the thread needs multiple concurrent transactions, we need more than one EntityManager in that thread because there is one-to-one relationship between EntityManager and EntityTransaction.


Q1. Are there any other situations when we need more than one EntityManager?

Q2. Upto my understanding, there should be only one EntityManagerFactory per Persitence Unit. Am I correct? If not, then what are those situations when we need multiple EntityManagerFactory per Persistence Unit?

  • 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-14T05:20:13+00:00Added an answer on May 14, 2026 at 5:20 am

    Q1: The EntityManager is best to be compared with the “good old” Hibernate Session: an unit of work (a simple business action, e.g. “logging in an user”, “placing an order”, etc). It is not necessarily tied to a single thread. You will only run in trouble if the different threads execute DB tasks which depends on each other inside a single unit of work. You would need to execute them in sync (preferably, in order in a single thread). If you for example have the business requirement to clean up some “old logs” when an user logs in (which reasonably wouldn’t disturb each other’s information), you can perfectly execute it in two separate threads inside a single unit of work.

    Q2: Your understanding is correct. You can however create more than one, but that wouldn’t make any sense nor have any benefits. It would only add significant overhead.

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

Sidebar

Related Questions

I am learning JPA. I read about persistence.xml file. It can contain more that
(learning c#) I have a C# WPF application which when a certain form is
I am learning JPA from this tutorial . I have some confusions in understanding
Hi i am learning about @ManyToMany relationship mapping using JPA. I more or less
learning Jquery and integrating with PHP - getting there, but have one last challenge
Learning asp.net mvc and whenever I worked we had to localize our application. Looked
I have a problem. I'm learning JPA. I'm using embedded OpenEJB container in unit
I am currently learning Spring. So far I have created a basic application consisting
I need to use an Entity framework with my application, and I have used
Learning Javascript and have a question about global variables. From my reading, most recommend

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.