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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T20:19:29+00:00 2026-05-11T20:19:29+00:00

I am new to openJPA. I have a scenario where, depending upon the server

  • 0

I am new to openJPA.

I have a scenario where, depending upon the server where my application is running, I need to change the settings to persistance.xml.
For eg. if its running on Server A, then it should use different database(different url), different password etc. and if the application is running on Server B then it should use different information.

And could you also tell me, which way should it be done, using datasource or simply putting properties under persistence-unit.

FYI I am using WS app. server 7 and RAD 7.5

Any type of help would be highly appreciated.

  • 1 1 Answer
  • 3 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-11T20:19:29+00:00Added an answer on May 11, 2026 at 8:19 pm

    You’re using an application server so you don’t need to set database connection settings in the persistence.xml file. You should be able to create a JNDI data source in your appserver and then use that. EAch server could have the data source have the same JNDI name and then there’ll be no need for any persistence.xml differences.

    Workshop, JPA, and DataSources seems particularly relevant to you. As does Setting up a JNDI data source in WebSphere 6.0/6.1 and WebSphere + JNDI + Spring Framework + Hibernate.

    Are you using Spring? If so, then the problem is easy to solve: you don’t put the data source information in your persistence.xml, you put it in your application context and that’ll have different configuration on each server.

    For example:

    <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="location" value="classpath:database.properties"/>
    </bean>
    
    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
        <property name="driverClassName" value="${database.class}"/>
        <property name="url" value="${database.url}"/>
        <property name="username" value="${database.username}"/>
        <property name="password" value="${database.password}"/>
    </bean>
    

    and each server could have a different database.properties file on each server (where each is in the classpath somewhere in this example):

    database.username=scratch
    database.password=scratch
    database.class=oracle.jdbc.OracleDriver
    database.url=jdbc:oracle:thin:@localhost:1521:XE
    

    Changing persistence.xml at runtime is going to be problematic as that’s not really how JPA is designed.

    Of course, you can use JNDI data sources with Spring also.

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

Sidebar

Related Questions

New to XML parsing.I need to read a group of arbitrary XML files. They
I have a Spring 3 application using openJPA as persistence management, following section works
I use OpenJPA 2.1 on WebSphere Application Server with a MySQL 5 DB. I
New to programming and need a little assistance. I have a WPF usercontrol used
I'm new to openjpa and get this warning. Existing column ... is incompatible with
New to PHP and MySQL, have heard amazing things about this website from Leo
I have an existing data model using openJPA and I am trying to integrate
NEW EDIT: I have narrowed my problem to this - i have a view
New question, but really close to need to refresh page in jquery mobile .
new to java and brand new to the site. I have a JLabel added

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.