工程里面的Hibernate的路径不是按默认位置放置的, 是通过设置路径指定到Hibernate.cfg.xml的位置.
工程里用到的映射文件res.hbm.xml和hibernate.cfg.xml方在同一个目录下.
然后在Hibernate.cfg.xml里面配置mapping resource="res.hbm.xml"运行的时候配置文件读取没有任何问题,但是加载resource时提示找不到:org.hibernate.MappingException: Resource: res.hbm.xml not found
at org.hibernate.cfg.Configuration.addResource(Configuration.java:479)
at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1465)
at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1433)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1414)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1390)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1344)

解决方案 »

  1.   

    应该用include把res.hbm.xml包进Hibernate.cfg.xml里
      

  2.   

    是你的mapping resource=""路径错误!没有找到指定路径。
    你没建一个包放置.hbm.xml文件吗?我觉得还是按它的规则放置好一点。
    因为有些规则就是规则。
      

  3.   

    谢谢各位,问题已得到解决……在配置文件中不需要指定映射文件,然后用configuration.addDirectory()加载映射文件所在的目录即可.configuration默认是读取classes下的映射文件,我们需要用addDirectory来重定向.