【发布时间】:2010-11-23 10:25:50
【问题描述】:
我有 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>
.....................
这是文件中最有趣的部分。 现在我必须设置缺失值:url、用户名、密码。 我正在尝试这样做:
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、username、passoword - 是命令行参数,所以我必须在运行时设置它们。
【问题讨论】:
-
我应该使用哪个命名空间来在 asp.net MVC 中使用 "AnnotationConfiguration" ?