5

I want to generate a hibernate.reveng.xml, but the "hibernate.connection.URL" in the hibernate.cfg.xml is a variable.

jdbc:jtds:sqlserver://${database.server.name}:1433/XXX_DB

so my question is how to let the hibernate-tool know where defined the variables?

user447586
  • 281
  • 2
  • 11
  • Why do you need to define this `jdbc:jtds:sqlserver://${database.server.name}:1433/XXX_DB` as a variable? – Lion Jan 04 '13 at 16:19
  • @Lion I have two different db servers, one for test, another for the live system. The properties file (include more than db server infos) for the hibernate.cfg.xml worked just fine under the intellij, but not any more since I switched back to the eclipse. Maybe you have better Idea for this case? – user447586 Jan 04 '13 at 16:47
  • I though before that you must have two different DB servers. The solution might be simple but it's a curiosity for me too. Let's wait for someone's reply. Thanks. – Lion Jan 04 '13 at 16:58
  • 4
    I am not fully understand you'r problem but if you want to pass dynamically value in hibernate.cfg.xml file then you can go this way. you need to create a object of the Configuration. like Configuration c = new Configuration(); c.configure(); for more information click on below link. http://www.hibernate-training-guide.com/configuration.html i don't know you are actually looking for this or not.. but just check it. – Jimit Tank Jan 25 '13 at 06:27

2 Answers2

0

You can specify, within an ant task, the path to a .properties file (which will have this content):

hibernate.connection.url=jdbc:mysql://127.0.0.1:1433/XXX_DB
hibernate.connection.username=xxx
hibernate.connection.password=yyy

then, in the ant task:

<hibernatetool ...>

   <jdbcconfiguration configurationfile="pathTo/your.cfg.cml"
                      propertyfile="pathTo/your.file.properties"/>

Hope it helps, Diego.

Diego Shevek
  • 486
  • 3
  • 15
0

It seems you are expecting, dynamic change of IP address in Data base connection URl and want a database connection at runtime.

  • If so you need to create a new hibernate Configuration instance in the project.

or

  • Change the machine name in the properties file and restart your server.

Usually,DB machine name should be decided before building your project. And these Machine details should be passed as an input to your build process and it will construct you DB URL accordingly(you can use Spring expression language to do this).

Sunil Kumar
  • 5,477
  • 4
  • 31
  • 38