开发者

hibernate changing cfg properties at runtime

I'm tr开发者_JS百科ying 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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜