我不想要hibernate.cfg.xml文件。相反,我希望通过我的代码完成所有配置,如下所示。
private static final SessionFactory factory;
private static final Properties properties;
static
{
properties = new Properties();
properties.setProperty("hibernate.connection.driver_class", "com.mysql.jdbc.Driver");
properties.setProperty("hibernate.connection.url", "jdbc:mysql://localhost:3306/books");
properties.setProperty("hibernate.connection.username", "jhtp7");
properties.setProperty("hibernate.connection.password", "password");
properties.setProperty("hibernate.show_sql", "com.mysql.jdbc.Driver");
properties.setProperty("hibernate.dialect", "org.hibernate.dialect.MySQLDialect");
factory = new Configuration().setProperties(properties).configure().
buildSessionFactory();
}
我已经尝试过上述方法。但我面临的问题是hibernate抛出了一个异常,写着"./hibernate.cfg.xml file missing
“。
保留hibernate.cfg.xml
文件真的是强制性的吗?
提前感谢
https://stackoverflow.com/questions/8830357
复制相似问题