首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >是否必须使用hibernate.cfg.xml文件进行配置

是否必须使用hibernate.cfg.xml文件进行配置
EN

Stack Overflow用户
提问于 2012-01-12 13:01:51
回答 2查看 19.5K关注 0票数 21

我不想要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文件真的是强制性的吗?

提前感谢

EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8830357

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档