开发者

how can I change the properties of the cfg.xml file?

I'm trying to change the properties of the hibernate.cfg.xml file programmatically here's what I did :

public class NewHibernateUtil {

 private final开发者_运维百科 SessionFactory sessionFactory;
 String host;
 String database;
 String username;
 String password;
 NewHibernateUtil(String host,String database,String username,String password){
     this.host=host;
     this.database=database;
     this.username=username;
     this.password=password;
     AnnotationConfiguration ac=new AnnotationConfiguration().configure();
     ac.setProperty("connection.url", "jdbc:mysql://"+host+"/"+database+"");  
     ac.setProperty("connection.username", username);  
     ac.setProperty("connection.password", password);             
     sessionFactory = ac.buildSessionFactory();         
 }    

public SessionFactory getSessionFactory() {
    return sessionFactory;
}    
}

but This doesn't work,it always uses the old properties in the hibernate.cfg.xml file.


I guess you need to specify full names of the properties when setting them manually:

ac.setProperty("hibernate.connection.url", "jdbc:mysql://"+host+"/"+database+"");        
ac.setProperty("hibernate.connection.username", username);
ac.setProperty("hibernate.connection.password", password);       
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜