映射XML在设置fetch-profile后无法验证

时间:2015-10-01 23:54:07

标签: xml hibernate dtd

基于documentation,我在类中添加了fetch-profile。 它没有验证,我也不知道为什么。

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.mycompany.nncloudrestservice.model">
  <class name="User" table="users">
    <meta attribute="class-description">
        Description under construction
    </meta>
    <id name="id" type="int">
        <column name="id_user" not-null="true"/>
        <generator class="native"/>
    </id>
    <property name="login" column="login" type="string"/>
    <property name="email" column="email" type="string"/>
    <property name="password" column="password" type="string"/>
    <property name="activated" column="activated" type="boolean"/> 
    <property name="info_to_admin" column="info_to_admin" type="string"/>
    <property name="session_id" column="session_id" type="string"/>
    <property name="registered" column="registered" type="date"/>
    <bag name="networks" cascade="all" table="networks" inverse="true" lazy="true">
        <key column="id_user" not-null="true"/>
        <one-to-many class="Network"/>
    </bag>
    <fetch-profile name="user-with-networks">
      <fetch association="networks" style="join"/>
    </fetch-profile>
    <one-to-one name="performance_settings" cascade="all" class="PerformanceSettings"></one-to-one>
  </class>
</hibernate-mapping>

验证结果:

Element type "fetch-profile" must be declared. [23] 
Element type "fetch" must be declared. [24] 
The content of element type "class" must match "(meta*,subselect?,cache?,synchronize*,comment?,tuplizer*,(id|composite-id),discriminator?,natural-id?,(version|timestamp)?,(property|many-to-one|one-to-one|component|dynamic-component|properties|any|map|set|list|bag|idbag|array|primitive-array)*,((join*,subclass*)|joined-subclass*|union-subclass*),loader?,sql-insert?,sql-update?,sql-delete?,filter*,resultset*,(query|sql-query)*)". [27] 

完全奇怪的是,特别是在发现在DTD中显式声明了fetch-profile之后:

<!ELEMENT class (
    meta*,
    subselect?,
    cache?,
    synchronize*,
    comment?,
    tuplizer*,
    (id|composite-id),
    discriminator?,
    natural-id?,
    (version|timestamp)?,
    (property|many-to-one|one-to-one|component|dynamic-component|properties|any|map|set|list|bag|idbag|array|primitive-array)*,
    ((join*,subclass*)|joined-subclass*|union-subclass*),
    loader?,sql-insert?,sql-update?,sql-delete?,
    filter*,
    fetch-profile*,
    resultset*,
    (query|sql-query)*
)>

1 个答案:

答案 0 :(得分:2)

Hibernate 3.5引入了获取配置文件功能。在此之前,DTD不包含此标记。您的验证器捕获过时版本的可能性非常高。 根据{{​​3}},你应该注意类路径上没有3.0个罐子。 您还可能希望将SGML_CATALOG_FILES(this solution)设置为DTD的本地副本,以便测试进一步的更改。