我有hibernate.cfg.xml文件。運行時休眠配置
<session-factory>
<!-- Database connection settings -->
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url"></property>
<property name="connection.username"></property>
<property name="connection.password"></property>
<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">1</property>
.....................
這是最有趣的部分文件。 現在我必須設置缺失值:網址,用戶名,密碼。 我想以這樣的方式來做到:
public static void SetSessionFactory() {
try {
AnnotationConfiguration conf = new AnnotationConfiguration().configure();
// <!-- Database connection settings -->
conf.setProperty("connection.url", URL);
conf.setProperty("connection.username", USERNAME);
conf.setProperty("connection.password", PASSWORD);
SESSION_FACTORY = conf.buildSessionFactory();
} catch (Throwable ex) {
// Log exception!
throw new ExceptionInInitializerError(ex);
}
}
,但它只是加載從hibernate.cfg.xm我的配置,不改變任何財產......
URL,用戶名,passoword - 被命令行參數,所以我必須在運行時設置它們。
哪個命名空間應該用於在asp.net MVC中使用「AnnotationConfiguration」? – bluwater2001 2010-03-26 18:27:42