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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T13:22:28+00:00 2026-05-20T13:22:28+00:00

I have a fairly standard Java EE6 web application using JPA 2 with dependency

  • 0

I have a fairly standard Java EE6 web application using JPA 2 with dependency injection connecting to a MySQL database and everything is working fine. What I would like to do now is have this application interact with the databases of other applications we have installed at a clients site – essentially acting as a single point of control for our other application installs.

What I’m struggling with is how best to perform the interaction with the other databases. Ideally I would like to create an EntityManager for each install and interact using JPA but I can’t see any way to set this up. I may, for example, have 5 installs (and therefore databases) of one application type and the master control application won’t know about the other installs until runtime. This seems to preclude using dependency injection of an EntityManager and all the automatic transaction demacation etc etc. The alternative option is to just create a DataSource and do the interactions manually. While flexible this clearly requires a lot more effort.

So, my question really is how do I best tackle this problem?

  • 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-20T13:22:29+00:00Added an answer on May 20, 2026 at 1:22 pm

    I’m also looking into this, and so far I have found the following blog post that describes a way to do it
    http://ayushsuman.blogspot.com/2010/06/configure-jpa-during-run-time-dynamic.html :

    Removed all your database properties from persistance.xml

    <persistence>
    <persistence-unit name="jpablogPUnit" transaction-type="RESOURCE_LOCAL">
    <class>com.suman.Company</class>
    </persistence-unit>
    </persistence>
    

    Changed your java file where you are configuring entityManager, in our case TestApplication.java

    package com.suman;
    
    import java.util.HashMap;
    import java.util.Map;
    import javax.persistence.EntityManager;
    import javax.persistence.EntityManagerFactory;
    import javax.persistence.Persistence;
    import org.apache.log4j.Logger;
    
    /**
    * @author Binod Suman
    */
    public class TestApplication {
    
    Logger log = Logger.getLogger(TestApplication.class);
    public static void main(String[] args) {
    TestApplication test = new TestApplication();
    test.saveCompany();
    }
    
    public void saveCompany(){
    log.info("Company data is going to save");
    EntityManagerFactory emf;
    Map properties = new HashMap();
    properties.put("hibernate.connection.driver_class", "com.mysql.jdbc.Driver");
    properties.put("hibernate.connection.url", "jdbc:mysql://localhost:3306/sumandb");
    properties.put("hibernate.connection.username", "root");
    properties.put("hibernate.connection.password", "mysql");
    properties.put("hibernate.dialect", "org.hibernate.dialect.MySQLDialect");
    properties.put("hibernate.show-sql", "true");
    //emf = Persistence.createEntityManagerFactory("jpablogPUnit");
    emf = Persistence.createEntityManagerFactory("jpablogPUnit",properties);
    EntityManager entityManager = (EntityManager) emf.createEntityManager();
    entityManager.getTransaction().begin();
    Company company = new Company(120,"TecnoTree","Espoo, Finland");
    entityManager.persist(company);
    entityManager.getTransaction().commit();
    log.info("Company data has been saved");
    }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a fairly small MySQL database (a Textpattern install) on a server that
We have a Java web application that uses Spring and Hibernate and has a
I came across a fairly old Java web application that made use of servlets
I have a master project that's using a fairly standard source tree approach +
I have a fairly standard inheritance situation in my current LINQ-to-SQL project. I have
I have a fairly standard rails app and would like to be able to
I have a fairly simple addition to the HTTP standard. An ambitious goal I
We have fairly large C++ application which is composed of about 60 projects in
I have a fairly simple ASP.NET 2.0 menu control using a sitemap file and
I have a fairly good feel for what MySQL replication can do. I'm wondering

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.