• 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

how to modify hibernate.cfg.xml at runtime?

 
Ranch Hand
Posts: 127
Android Firefox Browser Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello Experts,
how do i edit database's username and password at runtime ? (sometimes IP address also may change)..
for this i need to edit hibernate.cfg.xml file ..
below i smy hibernate.cfg.xml 's details.



thanks 4 your time !
help
 
Bartender
Posts: 1210
25
Android Python PHP C++ Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Piyush,

Since IP/credentials are not static, I feel they shouldn't be in a configuration file at all. Instead, some component which tracks current database IP/credentials should respond to changes by closing the current SessionFactory, create a new Configuration object programmatically, and create a new SessionFactory from that. Rest of the components should start using this new SessionFactory.

Programmatically modifying the xml file and reloading it is unnecessarily complicated, since the goal is just to change the active Configuration.

Cheers
Karthik
 
Karthik Shiraly
Bartender
Posts: 1210
25
Android Python PHP C++ Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, on 2nd thoughts, you can use a mixed approach, since only few of the properties change at runtime, while the rest of the Configuration remains same. So do use a configuration file, but when there's runtime change, use the 'Configuration.setProperty()' method to change values. You still need to close the old SessionFactory and create a new one. But you can use the same Configuration object.
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm curious what kind of setup would ever require this to change at runtime.
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

David Newton wrote:I'm curious what kind of setup would ever require this to change at runtime.



I'm running into this issue. Trying to write a utility in Java that reads a file in a certain format and loads it into the database used by a certain content-management system. The mapping files mirror the CMS's own standard structure, so they shouldn't change, and the CMS generally only runs with MySQL as the database, but the server, schema, username and password could be anything.

I've built a Swing-based wizard to collect that information and also have a class that collects it from the command-line. I'm trying to patch it in as follows:


However, I still get the log-message


followed by the error



So I'd be interested in a good answer to this question as well.
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That seems like a classpath issue.
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'd like to know if someone have a solution for this idea? because I need to do the same, modify the property "connection.password" in hibertate.cfg.xml at runtime, firstly this password is encrypted in my xml and then I have to decrypt it. Actually I have the classes to do that, only I need this part! How can I do this? Some Ideas?

In advance thank you very much.
 
Carlos Oviedo
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Carlos Oviedo wrote:I'd like to know if someone have a solution for this idea? because I need to do the same, modify the property "connection.password" in hibertate.cfg.xml at runtime, firstly this password is encrypted in my xml and then I have to decrypt it. Actually I have the classes to do that, only I need this part! How can I do this? Some Ideas?

In advance thank you very much.




I find the solution to my case!!!

I modified in my code this part:

to this:


"hibernate." is very important in the properties.


Page helped me:
http://stackoverflow.com/questions/1341871/hibernate-configuration-on-runtime
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic