【问题标题】:Hibernate Configuration with only hibernate.properties file. Without any hibernate.cfg.xml只有 hibernate.properties 文件的休眠配置。没有任何 hibernate.cfg.xml
【发布时间】:2016-06-29 13:31:54
【问题描述】:

是否可以只使用hibernate.properties 文件来配置休眠而没有任何hibernate.cfg.xml 文件?

我已经在 hibernate.properties 文件中定义了所需的属性。

hibernate.dialect=org.hibernate.dialect.MySQLDialect
hibernate.connection.driver_class=com.mysql.jdbc.Driver
hibernate.connection.url=jdbc:mysql://localhost:3306/dev
hibernate.connection.username=root
hibernate.connection.password=
hibernate.connection.pool_size=1
hibernate.show_sql=true
hibernate.format_sql=true
hibernate.cache.provider_class=org.hibernate.cache.NoCacheProvider
hibernate.hbm2ddl.auto=update

休眠显示:

Loaded properties from resource hibernate.properties: {hibernate.connection.driver_class=com.mysql.jdbc.Driver, hibernate.cache.provider_class=org.hibernate.cache.NoCacheProvider, hibernate.dialect=org.hibernate.dialect.MySQLDialect, hibernate.format_sql=true, hibernate.connection.username=root, hibernate.hbm2ddl.auto=update, hibernate.connection.url=jdbc:mysql://localhost:3306/dev, hibernate.bytecode.use_reflection_optimizer=false, hibernate.show_sql=true, hibernate.connection.password=****, hibernate.connection.pool_size=1}

但它仍然要求cfg.xml

Exception in thread "main" org.hibernate.internal.util.config.ConfigurationException: Could not locate cfg.xml resource [hibernate.cfg.xml]

【问题讨论】:

  • 有可能。看到这个tutorial。将 hibernate.properties 放在应用程序 CLASSPATH 的根目录中

标签: java xml hibernate properties-file


【解决方案1】:

有可能

SessionFactory factory = new Configuration().buildSessionFactory();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-09-22
    • 1970-01-01
    • 1970-01-01
    • 2015-04-06
    • 2014-07-17
    • 2013-04-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多