【问题标题】:Can not load the hbm file in hiberante无法在休眠中加载hbm文件
【发布时间】:2011-03-19 21:56:30
【问题描述】:

我正在尝试从 JBoss 网站上学习 Hibernate 教程。基本上它是一个非常简单的应用程序,可以将事件添加到数据库中。

有一个 org.hibernate.tutorial.domain.Event 和一个 Event.hbm.xml 文件。

问题是: 无论我在做什么,当我初始化配置对象时,我都会得到一个 org.hibernate.MappingNotFoundException 资源:Event.hbm.xml not fohund。 我将其初始化如下:

File hibernateCfgFile = new File("C:/Program Files/Development/IDE/workspace/Hibernate3.6/hibernate.cfg.xml");
        try {
            // Create the SessionFactory from hibernate.cfg.xml
            return new Configuration().configure(hibernateCfgFile).buildSessionFactory();
        }

我尝试在 hibernate.cfg.xml 文件中指定 hbm 文件的完整路径 但没有成功。

另一个奇怪的点是我必须指定 hibernate.cfg.xml 位置。没有,即使它在 src 文件夹中也找不到文件。

有什么想法吗??

【问题讨论】:

  • 向我们展示了休眠 cfg 文件

标签: java hibernate hibernate-mapping hibernate.cfg.xml


【解决方案1】:

首先,您应该将任何休眠(或其他资源)放在您的 java 类路径中。您的第二个问题是“程序文件”中的空间。我发现最好将可能需要以编程方式从文件系统读取的任何内容尽可能远离可怕的“程序文件”目录。

【讨论】:

    【解决方案2】:

    将您的映射文件放在根目录中 hibernate.cfg.xml 文件旁边。

    【讨论】:

      猜你喜欢
      • 2011-04-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-27
      • 2013-09-23
      • 2016-12-11
      • 1970-01-01
      相关资源
      最近更新 更多