1

I have an app which uses Hibernate 3.6.3 as the ORM. I created the hibernate.cfg.xml configuration file and added it to the build path. This works fine in my development environment. Now I need to create a jar for the production server with a dynamic DB connection credentials. I spent couple of hours on searching how to do it but all of the examples use:

  • Spring: which is not on the list of "blessed technologies",

  • Separate maven profiles: for which I need to now the production credentials (this won't happen).

Can I separate hibernate DB configurations or I need to pass it as parameter and configure hibernate programmatically?

Vlad Mihalcea
  • 142,745
  • 71
  • 566
  • 911
orwe
  • 233
  • 1
  • 3
  • 10

1 Answers1

1

You already proposed two solutions:

  • build-time configuration (using Maven), but you don't have the credentials at build-time

  • run-time configuration resolving, which can be done:

    1. Using Spring (which you can't use)

    2. Using your own programmatic mechanism:

      Configuration configuration = new Configuration();
      configuration.configure();
      
      configuration.setProperty("hibernate.connection.url", dbUrl);
      configuration.setProperty("hibernate.connection.username", dbUser);
      configuration.setProperty("hibernate.connection.password", dbPassword); 
      
      return configuration.buildSessionFactory();
      
Vlad Mihalcea
  • 142,745
  • 71
  • 566
  • 911
  • I hope there is a way to extract config to the MyConf.properties somehow but "configuration.setProperty" will do. – orwe Mar 31 '15 at 10:39