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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T03:18:02+00:00 2026-06-11T03:18:02+00:00

I want my persistence.xml to set some of its properties dynamically, to be specific:

  • 0

I want my persistence.xml to set some of its properties dynamically, to be specific:

<property name="hibernate.connection.password" value="password"/>
<property name="hibernate.connection.username" value="username"/>

I can build a class that could provide me the data I need, but I don’t know how to set the class up in a way that it works like this:

<property name="hibernate.connection.password" value="${my.clazz.pass}"/>
<property name="hibernate.connection.username" value="${my.clazz.user}"/>

I have tried to set the class up like this

public class clazz{

  String pass;
  String user;

  public clazz(){
    //do stuff to set pass and user
  }

  //getter/setter
}

But that does not work. I haven’t found a way here or in google, but I have seen the ${my.clazz.smth}-way several times.

So, how can I set that up? 🙂

Thanks in advance!

  • 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-06-11T03:18:04+00:00Added an answer on June 11, 2026 at 3:18 am

    So, resolved this a while ago, but I still didn’t answer:

    Anthony Accioly pointed me to the right direction:

    I added this to my applicationContext.xml’s entityManagerFactory

    <bean id="entityManagerFactory"
        class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="persistenceUnitPostProcessors">
            <bean class="my.package.SetupDatabase">
            </bean>
        </property>
        //the other stuff
    </bean>
    

    The corresponding class, in this case I use hibernate:

    package my.package;
    
    public class SetupDatabase implements PersistenceUnitPostProcessor {
    
        private String username;
        private String password;
        private String dbserver;
    
        public void SetupDatabase(){
            //do stuff to obtain needed information
        }
    
        public void postProcessPersistenceUnitInfo(MutablePersistenceUnitInfo pui) {
            pui.getProperties().setProperty("hibernate.connection.username", username );
            pui.getProperties().setProperty("hibernate.connection.password", password);
            pui.getProperties().setProperty("hibernate.connection.url", dbserver ); 
        }
    
    }
    

    This way the setup is done just once when starting the whole thing up, but the required data may be ‘outsourced’.

    Thanks again for pointing me to the right direction!

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

Sidebar

Related Questions

I have my default schema declared in persistence.xml as: <property name=hibernate.default_schema value=MYSCHEMA /> However,
I'm using persistence API and want to load jdbc URL from web.xml. URL should
I want to read environment variables inside persistence.xml file. Idea is that i don't
We have to rename persistence.xml to fool WebSphere 7 not to use its built-in
Want to know ways to store OBJECTS of a Class in some persistent storage.
want to know why String behaves like value type while using ==. String s1
how can i set openjpa to flush before query. When i change some values
We have some JPA entity classes which are currently under development and wouldn't want
I want to use Infinispan with hibernate second level cache. My application is running
I am developing a tool that handles some database entities using JPA2, with hibernate

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.