【问题标题】:Hibernate mapping-resource must be followed by either attribute specifications, ">" or "/>".'Hibernate 映射资源必须后跟属性规范,“>”或“/>”。
【发布时间】:2011-08-19 17:00:08
【问题描述】:

我的 hibernate.cfg.xml 中的映射资源有问题 - 我明白了

Element type "mapping-resource" must be followed by either attribute specifications, ">" or "/>".'

我的 hibernate.cfg.xml 看起来像

<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
    "-//Hibernate/Hibernate Configuration DTD//EN"
    "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> 
<hibernate-configuration>

   <session-factory>
      <property name="datasourceName">java:jboss/datasources/MySqlDS</property>
      <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
        <mapping-resource="com/mycompany/myapp/common/businessobjects/User.hbm.xml"/>
        <mapping-resource="com/mycompany/myapp/common/businessobjects/Company.hbm.xml"/>
        <mapping-    resource="com/mycompany/myapp/common/businessobjects/ServerSettings.hbm.xml"/>
        <mapping-resource="com/mycompany/myapp/common/businessobjects/Station.hbm.xml"/>
   </session-factory>
</hibernate-configuration>

不确定是什么问题?语法似乎正确?我将我的地图资源资料基于此处的信息

http://docs.jboss.org/hibernate/core/3.3/reference/en/html/session-configuration.html

【问题讨论】:

  • 大概mapping-____resource 中的大空白是在您复制 XML 时发生的?

标签: xml hibernate


【解决方案1】:

您误读了规范(参见第 3.7 章)。它需要看起来像

<mapping resource="com/mycompany/myapp/common/businessobjects/User.hbm.xml"/>

你有一个 - (减号),它应该是一个空格。 xml标签是“映射”属性是“资源”

【讨论】:

    【解决方案2】:

    这是糟糕的 XML 语法。你不能写&lt;name="something"/&gt;;它必须是&lt;name attrname="something"/&gt;。 XML 解析器正在抱怨,因为它在 =" 之前找不到属性名称。

    您链接到的文档根本没有提到mapping-resource,所以很难说正确的语法是什么。不过,你可以试试

    <mapping-resource>com/mycompany/myapp/common/businessobjects/User.hbm.xml</mapping-resource>
    

    这有一定的工作机会。 (至少它是格式良好的 XML,但我不能说它是否是您的工具所期望的特定结构)。

    【讨论】:

      猜你喜欢
      • 2015-09-14
      • 2017-03-12
      • 2012-01-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-27
      相关资源
      最近更新 更多