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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:43:22+00:00 2026-05-26T05:43:22+00:00

The @Multitenant support in Eclipselink 2.3 looks really interesting, but I’m having a hard

  • 0

The @Multitenant support in Eclipselink 2.3 looks really interesting, but I’m having a hard time understanding how to use it in a JSF or EJB which injects an EntityManager with @PersistenceContext. The EclipseLink docs are pretty clear that @PersistenceContext injection doesn’t work in this case, but you could inject an EntityManagerFactory via @PersistenceUunit instead.

Still, what I’m not seeing is how to manage the lifecycle of an EntityManager you might create via injected EntityManagerFactory.createEntityManager() – in particular, when to close the resulting EntityManager, and how to participate in transactions.

Has anyone gotten this to work? Or am I missing something obvious?

See also: http://wiki.eclipse.org/EclipseLink/Examples/JPA/Multitenant

UPDATE

I had some success with @PersistenceContext (EntityManager) injection and then passing parameters to EclipseLink via session listener. I’m not 100% sure this is the right answer and would appreciate confirmation that it isn’t creating a non-obvious race condition or thread-safety issue.

For example:

public static class TenantListener extends SessionEventAdapter {

    @Override
    public void postAcquireClientSession(SessionEvent event) {
        long tenantId = **business logic**;
        event.getSession().setProperty("eclipselink.tenant-id", tenantId);
    }
}
  • 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-26T05:43:22+00:00Added an answer on May 26, 2026 at 5:43 am

    Using events is fine.

    You could also inject the EntityManager and set the property, or inject the EntityManagerFactory and use joinTransaction() to join the active JTA transaction.

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

Sidebar

Related Questions

I am working on my second multitenant MVC application. My first did not use
Having in mind that each webapp has its own separate database (but all databases
For multitenant databases, to you name tables differently based on: Whether the table will
We plan to change our multitenant ordering system on the intranet. All products of
A multitennant database for use by telsales agents, a table contains the prospect leads
I am making heavy use of async requests by Javascript to the webserver. Since
We have a multi-tenant system with a separate database per tenant (but with the
Can Tomcat tell mod_jk's load balancer to use another worker when overloaded? If so,
With Sync Framework 2.1, batching seems to have got in-built support, so in some
I am trying to use domain masking to simulate multi-tenant access to my application.

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.