Reputation: 3819
I'm trying to change cfg properties at runtime. For example:
cfg.setProperty("hibernate.connection.url")
The problem is that it works only when this property is not defined in the cfg file itself, meaning, it doesn't override.
Can it be done in some way?
Upvotes: 1
Views: 3732
Reputation: 3889
when you run
Configuration cfg = new Configuration().configure();
the .configure()
reads the data from the XML, and it has a higher priority over the programmatic configuration.
However, if you remove the .configure
, all the configuration will be "read" from the settings that you will pass. For example:
Configuration configuration = new Configuration()
.setProperty( "hibernate.connection.driver_class", "org.postgresql.Driver" )
.setProperty( "hibernate.dialect","org.hibernate.dialect.PostgreSQLDialect")
[...snip...]
.addAnnotatedClass( com.myPackage.MyClass.class )
[...] ;
will set all the properties at runtime.
Upvotes: 3