Setting properties programmatically in Hibernate

前端 未结 5 939
别那么骄傲
别那么骄傲 2020-11-30 11:27

How can I ensure that all properties are loaded from hibernate.cfg.xml, then add additional properties programmatically? I saw the following code snippet but it looks like a

5条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-30 11:31

    You code snippet should load hibernate.cfg.xml from the root of the classpath and then add or overwrite the configuration properties programmatically . So , please make sure that your so called the "existing one hibernate.cfg.xml " is on the root of the classpath.

    If your "existing one hibernate.cfg.xml " is not on root of the classpath , but in some package , you can load it by specifying its package path in the configure() , likes

    Configuration config = new Configuration();
    config.configure("package1/package2/hibernate.cfg.xml");
    config.setProperty("hibernate.connection.username", "update" );
    config.setProperty("hibernate.connection.password", "defgh629154" ); 
    

提交回复
热议问题