简体   繁体   中英

How to externalize Hibernate 3.6 configuration

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?

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(); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM