1

我是hibernate的新手,一直在尝试从命令行(windows)运行SchemaExport hdm2ddl工具: java -cp "lib/*" org.hibernate.tool.hbm2ddl.SchemaExport --config=src/hibernate.cfg.xml --create src/hello/Message.hbm.xml

我的目录结构如下:

- HelloWorld
    - bin
    - lib (all of the required jars - list omitted for brevity)
    - src
        - hello (HelloWorld.java, Message.java & Message.hbm.xml)
        - persistence (HibernateUtil.java)
        - hibernate.cfg.xml
        - log4j.properties

尝试运行该命令会产生以下错误:

log4j:WARN No appenders could be found for logger (org.jboss.logging).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
org.hibernate.internal.util.config.ConfigurationException: Could not locate cfg.xml resource [src/hibernate.cfg.xml]
        at org.hibernate.boot.cfgxml.internal.ConfigLoader.loadConfigXmlResource(ConfigLoader.java:53)
        at org.hibernate.boot.registry.StandardServiceRegistryBuilder.configure(StandardServiceRegistryBuilder.java:163)
        at org.hibernate.tool.hbm2ddl.SchemaExport.buildStandardServiceRegistry(SchemaExport.java:579)
        at org.hibernate.tool.hbm2ddl.SchemaExport.main(SchemaExport.java:546)

到目前为止我的研究:

  1. 该命令找不到 hibernate.cfg.xml 文件。将命令中文件的拼写更改为错误的拼写会产生相同的错误。
  2. 将 cfg.xml 文件复制到类路径 (lib) 和 HelloWorld 目录中。错误仍然存​​在。

这基本上是“Java Persistence with Hibernate”中的示例,但从命令行运行它而不是使用 ant。

4

0 回答 0