映射 XML 在设置 fetch-profile 后未验证
Mapping XML doesn't validate after setting fetch-profile
基于documentation,我在class 中附加了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 中明确声明之后:
<!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)*
)>
Hibernate 3.5 引入了提取配置文件功能。在此之前,DTD 不包含此标记。您的验证器捕获过时版本的可能性非常高。
根据 this solution 这里你应该注意 class 路径上没有 3.0 罐子。
您可能还想将 SGML_CATALOG_FILES (see here) 设置为 DTD 的本地副本,只是为了测试进一步的更改。
基于documentation,我在class 中附加了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 中明确声明之后:
<!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)*
)>
Hibernate 3.5 引入了提取配置文件功能。在此之前,DTD 不包含此标记。您的验证器捕获过时版本的可能性非常高。 根据 this solution 这里你应该注意 class 路径上没有 3.0 罐子。 您可能还想将 SGML_CATALOG_FILES (see here) 设置为 DTD 的本地副本,只是为了测试进一步的更改。