• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Externalize connection URL username and password from hibernate.config.xml

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is it possible to externalize some of the session factory parameters like connection.url, connection.username, connection.password from the hibernate.config.xml file ?
I wanted to use the same hiberante.config.xml across our QA, UAT and prod environments, instead of creating a difference hibernate.config.xml file for each environment.
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you are using a Container/As that has Datasources, you can point your config to a datasource instead.

Mark
 
Vamshi Madhavaram
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Mark, We do not have a application server/container or external datasource.
Ours is a simple RMI server. So we rely on hibernate database sessions.
 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK, well another option is to build up the Factory through code for those properties, but I am not sure if I would choose that route. No real reason except it doesn't feel right to me, like it is ok, but not perfect kind of gut feeling.

Mark
 
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What about using XML External Entity references? I am not highly expert on this, found the information on the "Java Persistence with Hibernate" book, Chapter 3, Pg. 136-137.

Step 1: Define a globals.dtd file where you define external XML entities like the following:



Step 2: Include the global dtd file containing entities into you DOCTYPE definition in hibernate.cfg.xml file.



Step 3: In the hibernate.cfg.xml file refer those entities as replaceable parameters (hope following formats well!).




Step 3: Make sure the globals.dtd file is there on the classpath for the parser to find it out.

Step 4: We have an Ant build file to include the correct globals.dtd file for different environment and to build the corresponding JAR file at deployment time.

And good news is that it worked for us. Hope this helps.

- Susanta
[ November 05, 2007: Message edited by: Susanta Chatterjee ]
 
Vamshi Madhavaram
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Susantha.
I will try out your solution.
For now i used hibernate.properties to externalize these database values and then kept only the mappings in the hibernate.config.xml and it is working for me. Now instead of having 3 different hibernate.config.xml files for each environment I have 3 different hibernate.properties files.

This solved my purpose becoz i dont want to maintain the same mappings in 3 different files.
 
reply
    Bookmark Topic Watch Topic
  • New Topic