From 0237e07f40cbd786f89f35ff4a93a91a240d4247 Mon Sep 17 00:00:00 2001
From: Marius Dumitru Florea <marius@xwiki.com>
Date: Wed, 31 Aug 2016 12:01:58 +0300
Subject: [PATCH] Revert "XWIKI-13468: The query used by the Document Tree to
 get the nested child pages is very costly" * Too much duplication. Better
 move the hierarchy mapping in a separate file.

This reverts commit da8a821d26282ad5853de41f8ef1ea94d766321a.

(cherry picked from commit a9adeb63f0551b7e5a55f99265892ad16f38be8c)
---
 .../src/main/resources/xwiki.db2.hbm.xml      | 126 ------------------
 .../src/main/resources/xwiki.derby.hbm.xml    | 126 ------------------
 .../src/main/resources/xwiki.mssql.hbm.xml    | 126 ------------------
 .../src/main/resources/xwiki.oracle.hbm.xml   | 126 ------------------
 .../main/resources/xwiki.postgresql.hbm.xml   | 126 ------------------
 5 files changed, 630 deletions(-)

diff --git a/xwiki-platform-core/xwiki-platform-oldcore/src/main/resources/xwiki.db2.hbm.xml b/xwiki-platform-core/xwiki-platform-oldcore/src/main/resources/xwiki.db2.hbm.xml
index 7781336ce1f..9c1369f1846 100644
--- a/xwiki-platform-core/xwiki-platform-oldcore/src/main/resources/xwiki.db2.hbm.xml
+++ b/xwiki-platform-core/xwiki-platform-oldcore/src/main/resources/xwiki.db2.hbm.xml
@@ -434,130 +434,4 @@
             <generator class="assigned" />
         </id>
     </class>
-
-    <!--                        -->
-    <!-- Nested Pages Hierarchy -->
-    <!--                        -->
-
-    <!-- When displaying the page hierarchy (e.g. using the tree widget) we need to get information from 
-        both the documents table and the spaces table. Each of these tables contains some information that is 
-        not found on the other. The documents table contains the terminal pages while the spaces table contains 
-        the "empty" spaces (no direct terminal child pages). In order to get all the needed information we need 
-        to perform a union or an outer join (between unrelated Hibernate entities). The Hibernate version we 
-        use doesn't support either (HHH-1050 and HHH-16) so we define a new entity XWikiPage that is mapped to 
-        a SQL query rather than to an existing table. The SQL query can be overwritten for specific databases 
-        if needed. See XWIKI-13468. In the future we could merge the documents and spaces tables into a single 
-        one (the pages table) -->
-    <class name="com.xpn.xwiki.internal.model.XWikiPage" mutable="false">
-        <subselect><![CDATA[
-            select XWS_REFERENCE as reference, false as terminal, XWS_NAME as name, XWS_PARENT as parent, XWS_HIDDEN as hidden
-                from xwikispace
-            union
-            select XWD_FULLNAME as reference, true as terminal, XWD_NAME as name, XWD_WEB as parent, XWD_HIDDEN as hidden
-                from xwikidoc
-                where XWD_TRANSLATION = 0 and XWD_NAME <> 'WebHome'
-        ]]></subselect>
-        <synchronize table="xwikidoc" />
-        <synchronize table="xwikispace" />
-        <id column="id" type="long" unsaved-value="undefined" />
-        <properties name="pageId">
-            <property name="reference" type="string" length="255" index="PAGE_REFERENCE" not-null="true" access="field" />
-            <property name="terminal" type="boolean" length="255" index="PAGE_TERMINAL" not-null="true" access="field" />
-        </properties>
-        <property name="name" type="string" length="255" index="PAGE_NAME" not-null="true" access="field" />
-        <property name="parent" type="string" length="255" index="PAGE_PARENT" access="field" />
-        <property name="hidden" type="boolean" length="255" index="PAGE_HIDDEN" not-null="true" access="field" />
-        <!-- In order to sort the child XWikiPages by translated title (with fall-back on the default title, 
-            see XWIKI-12832) we need to perform an outer join which is possible only between related entities thus 
-            we aggregate the page translations here. -->
-        <set name="translations" lazy="true" cascade="none" access="field">
-            <key property-ref="pageId">
-                <column name="reference" />
-                <column name="terminal" />
-            </key>
-            <one-to-many class="com.xpn.xwiki.internal.model.XWikiPageTranslation" />
-        </set>
-    </class>
-
-    <!-- The XWikiPage translations, needed for sorting XWikiPages by their localized title. The pages 
-        that correspond to "empty" spaces don't have associated translations. -->
-    <class name="com.xpn.xwiki.internal.model.XWikiPageTranslation" mutable="false">
-        <subselect><![CDATA[
-            select case when XWD_NAME = 'WebHome' then XWD_WEB else XWD_FULLNAME end as reference,
-                   case when XWD_NAME = 'WebHome' then false else true end as terminal,
-                   nullif(XWD_TITLE, '') as title, XWD_LANGUAGE as locale, XWD_DEFAULT_LANGUAGE as defaultLocale
-                from xwikidoc
-        ]]></subselect>
-        <synchronize table="xwikidoc" />
-        <id column="id" type="long" unsaved-value="undefined" />
-        <many-to-one name="page" property-ref="pageId" not-null="true" access="field">
-            <column name="reference" />
-            <column name="terminal" />
-        </many-to-one>
-        <property name="title" type="string" length="255" index="PAGE_TITLE" access="field" />
-        <property name="locale" type="string" index="PAGE_LOCALE" length="5" access="field" />
-        <property name="defaultLocale" type="string" index="PAGE_DEFAULT_LOCALE" length="5" access="field" />
-    </class>
-
-    <!--                         -->
-    <!-- Nested Spaces Hierarchy -->
-    <!--                         -->
-
-    <!-- This entity is used to represent the Nested Spaces hierarchy, which we don't use in practice 
-        (we normally use the Nested Pages hierarchy instead) but the Document Tree has an option to display it 
-        so we keep this entity for backward compatibility. Even though the page and the space entities are distinct 
-        in this hierarchy, a space can have both page and space children so we still need to query them together 
-        in order to support sort and pagination. -->
-    <class name="com.xpn.xwiki.internal.model.XWikiPageOrSpace" mutable="false">
-        <subselect><![CDATA[
-            select XWS_REFERENCE as reference, false as terminal, XWS_NAME as name,
-                   XWS_PARENT as parent, null as parentDoc, XWS_HIDDEN as hidden
-                from xwikispace
-            union
-            select XWD_FULLNAME as reference, true as terminal, XWD_NAME as name,
-                   XWD_WEB as parent, XWD_PARENT as parentDoc, XWD_HIDDEN as hidden
-                from xwikidoc
-                where XWD_TRANSLATION = 0
-        ]]></subselect>
-        <synchronize table="xwikidoc" />
-        <synchronize table="xwikispace" />
-        <id column="id" type="long" unsaved-value="undefined" />
-        <properties name="pageId">
-            <property name="reference" type="string" length="255" index="PAGE_REFERENCE" not-null="true" access="field" />
-            <property name="terminal" type="boolean" length="255" index="PAGE_TERMINAL" not-null="true" access="field" />
-        </properties>
-        <property name="name" type="string" length="255" index="PAGE_NAME" not-null="true" access="field" />
-        <property name="parent" type="string" length="255" index="PAGE_PARENT" access="field" />
-        <!-- This is needed in order to implement the deprecated Parent-Child hierarchy over Nested Spaces. 
-            Again, we keep it for backward compatibility because initially the tree view from the Page Index was 
-            displaying the Parent-Child hierarchy with pages grouped by spaces (not the pure Parent-Child hierarchy). -->
-        <property name="parentDoc" type="string" length="255" index="PAGE_PARENT_DOC" access="field" />
-        <property name="hidden" type="boolean" length="255" index="PAGE_HIDDEN" not-null="true" access="field" />
-        <set name="translations" lazy="true" cascade="none" access="field">
-            <key property-ref="pageId">
-                <column name="reference" />
-                <column name="terminal" />
-            </key>
-            <one-to-many class="com.xpn.xwiki.internal.model.XWikiPageOrSpaceTranslation" />
-        </set>
-    </class>
-
-    <!-- The entity that represents the page translations in the Nested Spaces hierarchy. This is needed 
-        in order to be able to sort the children of a space by their localized title. -->
-    <class name="com.xpn.xwiki.internal.model.XWikiPageOrSpaceTranslation" mutable="false">
-        <subselect><![CDATA[
-            select XWD_FULLNAME as reference, true as terminal, nullif(XWD_TITLE, '') as title,
-                   XWD_LANGUAGE as locale, XWD_DEFAULT_LANGUAGE as defaultLocale
-                from xwikidoc
-        ]]></subselect>
-        <synchronize table="xwikidoc" />
-        <id column="id" type="long" unsaved-value="undefined" />
-        <many-to-one name="page" property-ref="pageId" not-null="true" access="field">
-            <column name="reference" />
-            <column name="terminal" />
-        </many-to-one>
-        <property name="title" type="string" length="255" index="PAGE_TITLE" access="field" />
-        <property name="locale" type="string" index="PAGE_LOCALE" length="5" access="field" />
-        <property name="defaultLocale" type="string" index="PAGE_DEFAULT_LOCALE" length="5" access="field" />
-    </class>
 </hibernate-mapping>
diff --git a/xwiki-platform-core/xwiki-platform-oldcore/src/main/resources/xwiki.derby.hbm.xml b/xwiki-platform-core/xwiki-platform-oldcore/src/main/resources/xwiki.derby.hbm.xml
index 7781336ce1f..9c1369f1846 100644
--- a/xwiki-platform-core/xwiki-platform-oldcore/src/main/resources/xwiki.derby.hbm.xml
+++ b/xwiki-platform-core/xwiki-platform-oldcore/src/main/resources/xwiki.derby.hbm.xml
@@ -434,130 +434,4 @@
             <generator class="assigned" />
         </id>
     </class>
-
-    <!--                        -->
-    <!-- Nested Pages Hierarchy -->
-    <!--                        -->
-
-    <!-- When displaying the page hierarchy (e.g. using the tree widget) we need to get information from 
-        both the documents table and the spaces table. Each of these tables contains some information that is 
-        not found on the other. The documents table contains the terminal pages while the spaces table contains 
-        the "empty" spaces (no direct terminal child pages). In order to get all the needed information we need 
-        to perform a union or an outer join (between unrelated Hibernate entities). The Hibernate version we 
-        use doesn't support either (HHH-1050 and HHH-16) so we define a new entity XWikiPage that is mapped to 
-        a SQL query rather than to an existing table. The SQL query can be overwritten for specific databases 
-        if needed. See XWIKI-13468. In the future we could merge the documents and spaces tables into a single 
-        one (the pages table) -->
-    <class name="com.xpn.xwiki.internal.model.XWikiPage" mutable="false">
-        <subselect><![CDATA[
-            select XWS_REFERENCE as reference, false as terminal, XWS_NAME as name, XWS_PARENT as parent, XWS_HIDDEN as hidden
-                from xwikispace
-            union
-            select XWD_FULLNAME as reference, true as terminal, XWD_NAME as name, XWD_WEB as parent, XWD_HIDDEN as hidden
-                from xwikidoc
-                where XWD_TRANSLATION = 0 and XWD_NAME <> 'WebHome'
-        ]]></subselect>
-        <synchronize table="xwikidoc" />
-        <synchronize table="xwikispace" />
-        <id column="id" type="long" unsaved-value="undefined" />
-        <properties name="pageId">
-            <property name="reference" type="string" length="255" index="PAGE_REFERENCE" not-null="true" access="field" />
-            <property name="terminal" type="boolean" length="255" index="PAGE_TERMINAL" not-null="true" access="field" />
-        </properties>
-        <property name="name" type="string" length="255" index="PAGE_NAME" not-null="true" access="field" />
-        <property name="parent" type="string" length="255" index="PAGE_PARENT" access="field" />
-        <property name="hidden" type="boolean" length="255" index="PAGE_HIDDEN" not-null="true" access="field" />
-        <!-- In order to sort the child XWikiPages by translated title (with fall-back on the default title, 
-            see XWIKI-12832) we need to perform an outer join which is possible only between related entities thus 
-            we aggregate the page translations here. -->
-        <set name="translations" lazy="true" cascade="none" access="field">
-            <key property-ref="pageId">
-                <column name="reference" />
-                <column name="terminal" />
-            </key>
-            <one-to-many class="com.xpn.xwiki.internal.model.XWikiPageTranslation" />
-        </set>
-    </class>
-
-    <!-- The XWikiPage translations, needed for sorting XWikiPages by their localized title. The pages 
-        that correspond to "empty" spaces don't have associated translations. -->
-    <class name="com.xpn.xwiki.internal.model.XWikiPageTranslation" mutable="false">
-        <subselect><![CDATA[
-            select case when XWD_NAME = 'WebHome' then XWD_WEB else XWD_FULLNAME end as reference,
-                   case when XWD_NAME = 'WebHome' then false else true end as terminal,
-                   nullif(XWD_TITLE, '') as title, XWD_LANGUAGE as locale, XWD_DEFAULT_LANGUAGE as defaultLocale
-                from xwikidoc
-        ]]></subselect>
-        <synchronize table="xwikidoc" />
-        <id column="id" type="long" unsaved-value="undefined" />
-        <many-to-one name="page" property-ref="pageId" not-null="true" access="field">
-            <column name="reference" />
-            <column name="terminal" />
-        </many-to-one>
-        <property name="title" type="string" length="255" index="PAGE_TITLE" access="field" />
-        <property name="locale" type="string" index="PAGE_LOCALE" length="5" access="field" />
-        <property name="defaultLocale" type="string" index="PAGE_DEFAULT_LOCALE" length="5" access="field" />
-    </class>
-
-    <!--                         -->
-    <!-- Nested Spaces Hierarchy -->
-    <!--                         -->
-
-    <!-- This entity is used to represent the Nested Spaces hierarchy, which we don't use in practice 
-        (we normally use the Nested Pages hierarchy instead) but the Document Tree has an option to display it 
-        so we keep this entity for backward compatibility. Even though the page and the space entities are distinct 
-        in this hierarchy, a space can have both page and space children so we still need to query them together 
-        in order to support sort and pagination. -->
-    <class name="com.xpn.xwiki.internal.model.XWikiPageOrSpace" mutable="false">
-        <subselect><![CDATA[
-            select XWS_REFERENCE as reference, false as terminal, XWS_NAME as name,
-                   XWS_PARENT as parent, null as parentDoc, XWS_HIDDEN as hidden
-                from xwikispace
-            union
-            select XWD_FULLNAME as reference, true as terminal, XWD_NAME as name,
-                   XWD_WEB as parent, XWD_PARENT as parentDoc, XWD_HIDDEN as hidden
-                from xwikidoc
-                where XWD_TRANSLATION = 0
-        ]]></subselect>
-        <synchronize table="xwikidoc" />
-        <synchronize table="xwikispace" />
-        <id column="id" type="long" unsaved-value="undefined" />
-        <properties name="pageId">
-            <property name="reference" type="string" length="255" index="PAGE_REFERENCE" not-null="true" access="field" />
-            <property name="terminal" type="boolean" length="255" index="PAGE_TERMINAL" not-null="true" access="field" />
-        </properties>
-        <property name="name" type="string" length="255" index="PAGE_NAME" not-null="true" access="field" />
-        <property name="parent" type="string" length="255" index="PAGE_PARENT" access="field" />
-        <!-- This is needed in order to implement the deprecated Parent-Child hierarchy over Nested Spaces. 
-            Again, we keep it for backward compatibility because initially the tree view from the Page Index was 
-            displaying the Parent-Child hierarchy with pages grouped by spaces (not the pure Parent-Child hierarchy). -->
-        <property name="parentDoc" type="string" length="255" index="PAGE_PARENT_DOC" access="field" />
-        <property name="hidden" type="boolean" length="255" index="PAGE_HIDDEN" not-null="true" access="field" />
-        <set name="translations" lazy="true" cascade="none" access="field">
-            <key property-ref="pageId">
-                <column name="reference" />
-                <column name="terminal" />
-            </key>
-            <one-to-many class="com.xpn.xwiki.internal.model.XWikiPageOrSpaceTranslation" />
-        </set>
-    </class>
-
-    <!-- The entity that represents the page translations in the Nested Spaces hierarchy. This is needed 
-        in order to be able to sort the children of a space by their localized title. -->
-    <class name="com.xpn.xwiki.internal.model.XWikiPageOrSpaceTranslation" mutable="false">
-        <subselect><![CDATA[
-            select XWD_FULLNAME as reference, true as terminal, nullif(XWD_TITLE, '') as title,
-                   XWD_LANGUAGE as locale, XWD_DEFAULT_LANGUAGE as defaultLocale
-                from xwikidoc
-        ]]></subselect>
-        <synchronize table="xwikidoc" />
-        <id column="id" type="long" unsaved-value="undefined" />
-        <many-to-one name="page" property-ref="pageId" not-null="true" access="field">
-            <column name="reference" />
-            <column name="terminal" />
-        </many-to-one>
-        <property name="title" type="string" length="255" index="PAGE_TITLE" access="field" />
-        <property name="locale" type="string" index="PAGE_LOCALE" length="5" access="field" />
-        <property name="defaultLocale" type="string" index="PAGE_DEFAULT_LOCALE" length="5" access="field" />
-    </class>
 </hibernate-mapping>
diff --git a/xwiki-platform-core/xwiki-platform-oldcore/src/main/resources/xwiki.mssql.hbm.xml b/xwiki-platform-core/xwiki-platform-oldcore/src/main/resources/xwiki.mssql.hbm.xml
index 360c732ade4..9da5e0c2750 100644
--- a/xwiki-platform-core/xwiki-platform-oldcore/src/main/resources/xwiki.mssql.hbm.xml
+++ b/xwiki-platform-core/xwiki-platform-oldcore/src/main/resources/xwiki.mssql.hbm.xml
@@ -436,130 +436,4 @@
             <generator class="assigned" />
         </id>
     </class>
-
-    <!--                        -->
-    <!-- Nested Pages Hierarchy -->
-    <!--                        -->
-
-    <!-- When displaying the page hierarchy (e.g. using the tree widget) we need to get information from 
-        both the documents table and the spaces table. Each of these tables contains some information that is 
-        not found on the other. The documents table contains the terminal pages while the spaces table contains 
-        the "empty" spaces (no direct terminal child pages). In order to get all the needed information we need 
-        to perform a union or an outer join (between unrelated Hibernate entities). The Hibernate version we 
-        use doesn't support either (HHH-1050 and HHH-16) so we define a new entity XWikiPage that is mapped to 
-        a SQL query rather than to an existing table. The SQL query can be overwritten for specific databases 
-        if needed. See XWIKI-13468. In the future we could merge the documents and spaces tables into a single 
-        one (the pages table) -->
-    <class name="com.xpn.xwiki.internal.model.XWikiPage" mutable="false">
-        <subselect><![CDATA[
-            select XWS_REFERENCE as reference, false as terminal, XWS_NAME as name, XWS_PARENT as parent, XWS_HIDDEN as hidden
-                from xwikispace
-            union
-            select XWD_FULLNAME as reference, true as terminal, XWD_NAME as name, XWD_WEB as parent, XWD_HIDDEN as hidden
-                from xwikidoc
-                where XWD_TRANSLATION = 0 and XWD_NAME <> 'WebHome'
-        ]]></subselect>
-        <synchronize table="xwikidoc" />
-        <synchronize table="xwikispace" />
-        <id column="id" type="long" unsaved-value="undefined" />
-        <properties name="pageId">
-            <property name="reference" type="string" length="255" index="PAGE_REFERENCE" not-null="true" access="field" />
-            <property name="terminal" type="boolean" length="255" index="PAGE_TERMINAL" not-null="true" access="field" />
-        </properties>
-        <property name="name" type="string" length="255" index="PAGE_NAME" not-null="true" access="field" />
-        <property name="parent" type="string" length="255" index="PAGE_PARENT" access="field" />
-        <property name="hidden" type="boolean" length="255" index="PAGE_HIDDEN" not-null="true" access="field" />
-        <!-- In order to sort the child XWikiPages by translated title (with fall-back on the default title, 
-            see XWIKI-12832) we need to perform an outer join which is possible only between related entities thus 
-            we aggregate the page translations here. -->
-        <set name="translations" lazy="true" cascade="none" access="field">
-            <key property-ref="pageId">
-                <column name="reference" />
-                <column name="terminal" />
-            </key>
-            <one-to-many class="com.xpn.xwiki.internal.model.XWikiPageTranslation" />
-        </set>
-    </class>
-
-    <!-- The XWikiPage translations, needed for sorting XWikiPages by their localized title. The pages 
-        that correspond to "empty" spaces don't have associated translations. -->
-    <class name="com.xpn.xwiki.internal.model.XWikiPageTranslation" mutable="false">
-        <subselect><![CDATA[
-            select case when XWD_NAME = 'WebHome' then XWD_WEB else XWD_FULLNAME end as reference,
-                   case when XWD_NAME = 'WebHome' then false else true end as terminal,
-                   nullif(XWD_TITLE, '') as title, XWD_LANGUAGE as locale, XWD_DEFAULT_LANGUAGE as defaultLocale
-                from xwikidoc
-        ]]></subselect>
-        <synchronize table="xwikidoc" />
-        <id column="id" type="long" unsaved-value="undefined" />
-        <many-to-one name="page" property-ref="pageId" not-null="true" access="field">
-            <column name="reference" />
-            <column name="terminal" />
-        </many-to-one>
-        <property name="title" type="string" length="255" index="PAGE_TITLE" access="field" />
-        <property name="locale" type="string" index="PAGE_LOCALE" length="5" access="field" />
-        <property name="defaultLocale" type="string" index="PAGE_DEFAULT_LOCALE" length="5" access="field" />
-    </class>
-
-    <!--                         -->
-    <!-- Nested Spaces Hierarchy -->
-    <!--                         -->
-
-    <!-- This entity is used to represent the Nested Spaces hierarchy, which we don't use in practice 
-        (we normally use the Nested Pages hierarchy instead) but the Document Tree has an option to display it 
-        so we keep this entity for backward compatibility. Even though the page and the space entities are distinct 
-        in this hierarchy, a space can have both page and space children so we still need to query them together 
-        in order to support sort and pagination. -->
-    <class name="com.xpn.xwiki.internal.model.XWikiPageOrSpace" mutable="false">
-        <subselect><![CDATA[
-            select XWS_REFERENCE as reference, false as terminal, XWS_NAME as name,
-                   XWS_PARENT as parent, null as parentDoc, XWS_HIDDEN as hidden
-                from xwikispace
-            union
-            select XWD_FULLNAME as reference, true as terminal, XWD_NAME as name,
-                   XWD_WEB as parent, XWD_PARENT as parentDoc, XWD_HIDDEN as hidden
-                from xwikidoc
-                where XWD_TRANSLATION = 0
-        ]]></subselect>
-        <synchronize table="xwikidoc" />
-        <synchronize table="xwikispace" />
-        <id column="id" type="long" unsaved-value="undefined" />
-        <properties name="pageId">
-            <property name="reference" type="string" length="255" index="PAGE_REFERENCE" not-null="true" access="field" />
-            <property name="terminal" type="boolean" length="255" index="PAGE_TERMINAL" not-null="true" access="field" />
-        </properties>
-        <property name="name" type="string" length="255" index="PAGE_NAME" not-null="true" access="field" />
-        <property name="parent" type="string" length="255" index="PAGE_PARENT" access="field" />
-        <!-- This is needed in order to implement the deprecated Parent-Child hierarchy over Nested Spaces. 
-            Again, we keep it for backward compatibility because initially the tree view from the Page Index was 
-            displaying the Parent-Child hierarchy with pages grouped by spaces (not the pure Parent-Child hierarchy). -->
-        <property name="parentDoc" type="string" length="255" index="PAGE_PARENT_DOC" access="field" />
-        <property name="hidden" type="boolean" length="255" index="PAGE_HIDDEN" not-null="true" access="field" />
-        <set name="translations" lazy="true" cascade="none" access="field">
-            <key property-ref="pageId">
-                <column name="reference" />
-                <column name="terminal" />
-            </key>
-            <one-to-many class="com.xpn.xwiki.internal.model.XWikiPageOrSpaceTranslation" />
-        </set>
-    </class>
-
-    <!-- The entity that represents the page translations in the Nested Spaces hierarchy. This is needed 
-        in order to be able to sort the children of a space by their localized title. -->
-    <class name="com.xpn.xwiki.internal.model.XWikiPageOrSpaceTranslation" mutable="false">
-        <subselect><![CDATA[
-            select XWD_FULLNAME as reference, true as terminal, nullif(XWD_TITLE, '') as title,
-                   XWD_LANGUAGE as locale, XWD_DEFAULT_LANGUAGE as defaultLocale
-                from xwikidoc
-        ]]></subselect>
-        <synchronize table="xwikidoc" />
-        <id column="id" type="long" unsaved-value="undefined" />
-        <many-to-one name="page" property-ref="pageId" not-null="true" access="field">
-            <column name="reference" />
-            <column name="terminal" />
-        </many-to-one>
-        <property name="title" type="string" length="255" index="PAGE_TITLE" access="field" />
-        <property name="locale" type="string" index="PAGE_LOCALE" length="5" access="field" />
-        <property name="defaultLocale" type="string" index="PAGE_DEFAULT_LOCALE" length="5" access="field" />
-    </class>
 </hibernate-mapping>
diff --git a/xwiki-platform-core/xwiki-platform-oldcore/src/main/resources/xwiki.oracle.hbm.xml b/xwiki-platform-core/xwiki-platform-oldcore/src/main/resources/xwiki.oracle.hbm.xml
index c60c36c993d..d2a9daf3216 100644
--- a/xwiki-platform-core/xwiki-platform-oldcore/src/main/resources/xwiki.oracle.hbm.xml
+++ b/xwiki-platform-core/xwiki-platform-oldcore/src/main/resources/xwiki.oracle.hbm.xml
@@ -459,130 +459,4 @@
             <generator class="assigned" />
         </id>
     </class>
-
-    <!--                        -->
-    <!-- Nested Pages Hierarchy -->
-    <!--                        -->
-
-    <!-- When displaying the page hierarchy (e.g. using the tree widget) we need to get information from 
-        both the documents table and the spaces table. Each of these tables contains some information that is 
-        not found on the other. The documents table contains the terminal pages while the spaces table contains 
-        the "empty" spaces (no direct terminal child pages). In order to get all the needed information we need 
-        to perform a union or an outer join (between unrelated Hibernate entities). The Hibernate version we 
-        use doesn't support either (HHH-1050 and HHH-16) so we define a new entity XWikiPage that is mapped to 
-        a SQL query rather than to an existing table. The SQL query can be overwritten for specific databases 
-        if needed. See XWIKI-13468. In the future we could merge the documents and spaces tables into a single 
-        one (the pages table) -->
-    <class name="com.xpn.xwiki.internal.model.XWikiPage" mutable="false">
-        <subselect><![CDATA[
-            select XWS_REFERENCE as reference, false as terminal, XWS_NAME as name, XWS_PARENT as parent, XWS_HIDDEN as hidden
-                from xwikispace
-            union
-            select XWD_FULLNAME as reference, true as terminal, XWD_NAME as name, XWD_WEB as parent, XWD_HIDDEN as hidden
-                from xwikidoc
-                where XWD_TRANSLATION = 0 and XWD_NAME <> 'WebHome'
-        ]]></subselect>
-        <synchronize table="xwikidoc" />
-        <synchronize table="xwikispace" />
-        <id column="id" type="long" unsaved-value="undefined" />
-        <properties name="pageId">
-            <property name="reference" type="string" length="255" index="PAGE_REFERENCE" not-null="true" access="field" />
-            <property name="terminal" type="boolean" length="255" index="PAGE_TERMINAL" not-null="true" access="field" />
-        </properties>
-        <property name="name" type="string" length="255" index="PAGE_NAME" not-null="true" access="field" />
-        <property name="parent" type="string" length="255" index="PAGE_PARENT" access="field" />
-        <property name="hidden" type="boolean" length="255" index="PAGE_HIDDEN" not-null="true" access="field" />
-        <!-- In order to sort the child XWikiPages by translated title (with fall-back on the default title, 
-            see XWIKI-12832) we need to perform an outer join which is possible only between related entities thus 
-            we aggregate the page translations here. -->
-        <set name="translations" lazy="true" cascade="none" access="field">
-            <key property-ref="pageId">
-                <column name="reference" />
-                <column name="terminal" />
-            </key>
-            <one-to-many class="com.xpn.xwiki.internal.model.XWikiPageTranslation" />
-        </set>
-    </class>
-
-    <!-- The XWikiPage translations, needed for sorting XWikiPages by their localized title. The pages 
-        that correspond to "empty" spaces don't have associated translations. -->
-    <class name="com.xpn.xwiki.internal.model.XWikiPageTranslation" mutable="false">
-        <subselect><![CDATA[
-            select case when XWD_NAME = 'WebHome' then XWD_WEB else XWD_FULLNAME end as reference,
-                   case when XWD_NAME = 'WebHome' then false else true end as terminal,
-                   nullif(XWD_TITLE, '') as title, XWD_LANGUAGE as locale, XWD_DEFAULT_LANGUAGE as defaultLocale
-                from xwikidoc
-        ]]></subselect>
-        <synchronize table="xwikidoc" />
-        <id column="id" type="long" unsaved-value="undefined" />
-        <many-to-one name="page" property-ref="pageId" not-null="true" access="field">
-            <column name="reference" />
-            <column name="terminal" />
-        </many-to-one>
-        <property name="title" type="string" length="255" index="PAGE_TITLE" access="field" />
-        <property name="locale" type="string" index="PAGE_LOCALE" length="5" access="field" />
-        <property name="defaultLocale" type="string" index="PAGE_DEFAULT_LOCALE" length="5" access="field" />
-    </class>
-
-    <!--                         -->
-    <!-- Nested Spaces Hierarchy -->
-    <!--                         -->
-
-    <!-- This entity is used to represent the Nested Spaces hierarchy, which we don't use in practice 
-        (we normally use the Nested Pages hierarchy instead) but the Document Tree has an option to display it 
-        so we keep this entity for backward compatibility. Even though the page and the space entities are distinct 
-        in this hierarchy, a space can have both page and space children so we still need to query them together 
-        in order to support sort and pagination. -->
-    <class name="com.xpn.xwiki.internal.model.XWikiPageOrSpace" mutable="false">
-        <subselect><![CDATA[
-            select XWS_REFERENCE as reference, false as terminal, XWS_NAME as name,
-                   XWS_PARENT as parent, null as parentDoc, XWS_HIDDEN as hidden
-                from xwikispace
-            union
-            select XWD_FULLNAME as reference, true as terminal, XWD_NAME as name,
-                   XWD_WEB as parent, XWD_PARENT as parentDoc, XWD_HIDDEN as hidden
-                from xwikidoc
-                where XWD_TRANSLATION = 0
-        ]]></subselect>
-        <synchronize table="xwikidoc" />
-        <synchronize table="xwikispace" />
-        <id column="id" type="long" unsaved-value="undefined" />
-        <properties name="pageId">
-            <property name="reference" type="string" length="255" index="PAGE_REFERENCE" not-null="true" access="field" />
-            <property name="terminal" type="boolean" length="255" index="PAGE_TERMINAL" not-null="true" access="field" />
-        </properties>
-        <property name="name" type="string" length="255" index="PAGE_NAME" not-null="true" access="field" />
-        <property name="parent" type="string" length="255" index="PAGE_PARENT" access="field" />
-        <!-- This is needed in order to implement the deprecated Parent-Child hierarchy over Nested Spaces. 
-            Again, we keep it for backward compatibility because initially the tree view from the Page Index was 
-            displaying the Parent-Child hierarchy with pages grouped by spaces (not the pure Parent-Child hierarchy). -->
-        <property name="parentDoc" type="string" length="255" index="PAGE_PARENT_DOC" access="field" />
-        <property name="hidden" type="boolean" length="255" index="PAGE_HIDDEN" not-null="true" access="field" />
-        <set name="translations" lazy="true" cascade="none" access="field">
-            <key property-ref="pageId">
-                <column name="reference" />
-                <column name="terminal" />
-            </key>
-            <one-to-many class="com.xpn.xwiki.internal.model.XWikiPageOrSpaceTranslation" />
-        </set>
-    </class>
-
-    <!-- The entity that represents the page translations in the Nested Spaces hierarchy. This is needed 
-        in order to be able to sort the children of a space by their localized title. -->
-    <class name="com.xpn.xwiki.internal.model.XWikiPageOrSpaceTranslation" mutable="false">
-        <subselect><![CDATA[
-            select XWD_FULLNAME as reference, true as terminal, nullif(XWD_TITLE, '') as title,
-                   XWD_LANGUAGE as locale, XWD_DEFAULT_LANGUAGE as defaultLocale
-                from xwikidoc
-        ]]></subselect>
-        <synchronize table="xwikidoc" />
-        <id column="id" type="long" unsaved-value="undefined" />
-        <many-to-one name="page" property-ref="pageId" not-null="true" access="field">
-            <column name="reference" />
-            <column name="terminal" />
-        </many-to-one>
-        <property name="title" type="string" length="255" index="PAGE_TITLE" access="field" />
-        <property name="locale" type="string" index="PAGE_LOCALE" length="5" access="field" />
-        <property name="defaultLocale" type="string" index="PAGE_DEFAULT_LOCALE" length="5" access="field" />
-    </class>
 </hibernate-mapping>
diff --git a/xwiki-platform-core/xwiki-platform-oldcore/src/main/resources/xwiki.postgresql.hbm.xml b/xwiki-platform-core/xwiki-platform-oldcore/src/main/resources/xwiki.postgresql.hbm.xml
index 083159dbf3e..00dc15df7d6 100644
--- a/xwiki-platform-core/xwiki-platform-oldcore/src/main/resources/xwiki.postgresql.hbm.xml
+++ b/xwiki-platform-core/xwiki-platform-oldcore/src/main/resources/xwiki.postgresql.hbm.xml
@@ -437,130 +437,4 @@
             <generator class="assigned" />
         </id>
     </class>
-
-    <!--                        -->
-    <!-- Nested Pages Hierarchy -->
-    <!--                        -->
-
-    <!-- When displaying the page hierarchy (e.g. using the tree widget) we need to get information from 
-        both the documents table and the spaces table. Each of these tables contains some information that is 
-        not found on the other. The documents table contains the terminal pages while the spaces table contains 
-        the "empty" spaces (no direct terminal child pages). In order to get all the needed information we need 
-        to perform a union or an outer join (between unrelated Hibernate entities). The Hibernate version we 
-        use doesn't support either (HHH-1050 and HHH-16) so we define a new entity XWikiPage that is mapped to 
-        a SQL query rather than to an existing table. The SQL query can be overwritten for specific databases 
-        if needed. See XWIKI-13468. In the future we could merge the documents and spaces tables into a single 
-        one (the pages table) -->
-    <class name="com.xpn.xwiki.internal.model.XWikiPage" mutable="false">
-        <subselect><![CDATA[
-            select XWS_REFERENCE as reference, false as terminal, XWS_NAME as name, XWS_PARENT as parent, XWS_HIDDEN as hidden
-                from xwikispace
-            union
-            select XWD_FULLNAME as reference, true as terminal, XWD_NAME as name, XWD_WEB as parent, XWD_HIDDEN as hidden
-                from xwikidoc
-                where XWD_TRANSLATION = 0 and XWD_NAME <> 'WebHome'
-        ]]></subselect>
-        <synchronize table="xwikidoc" />
-        <synchronize table="xwikispace" />
-        <id column="id" type="long" unsaved-value="undefined" />
-        <properties name="pageId">
-            <property name="reference" type="string" length="255" index="PAGE_REFERENCE" not-null="true" access="field" />
-            <property name="terminal" type="boolean" length="255" index="PAGE_TERMINAL" not-null="true" access="field" />
-        </properties>
-        <property name="name" type="string" length="255" index="PAGE_NAME" not-null="true" access="field" />
-        <property name="parent" type="string" length="255" index="PAGE_PARENT" access="field" />
-        <property name="hidden" type="boolean" length="255" index="PAGE_HIDDEN" not-null="true" access="field" />
-        <!-- In order to sort the child XWikiPages by translated title (with fall-back on the default title, 
-            see XWIKI-12832) we need to perform an outer join which is possible only between related entities thus 
-            we aggregate the page translations here. -->
-        <set name="translations" lazy="true" cascade="none" access="field">
-            <key property-ref="pageId">
-                <column name="reference" />
-                <column name="terminal" />
-            </key>
-            <one-to-many class="com.xpn.xwiki.internal.model.XWikiPageTranslation" />
-        </set>
-    </class>
-
-    <!-- The XWikiPage translations, needed for sorting XWikiPages by their localized title. The pages 
-        that correspond to "empty" spaces don't have associated translations. -->
-    <class name="com.xpn.xwiki.internal.model.XWikiPageTranslation" mutable="false">
-        <subselect><![CDATA[
-            select case when XWD_NAME = 'WebHome' then XWD_WEB else XWD_FULLNAME end as reference,
-                   case when XWD_NAME = 'WebHome' then false else true end as terminal,
-                   nullif(XWD_TITLE, '') as title, XWD_LANGUAGE as locale, XWD_DEFAULT_LANGUAGE as defaultLocale
-                from xwikidoc
-        ]]></subselect>
-        <synchronize table="xwikidoc" />
-        <id column="id" type="long" unsaved-value="undefined" />
-        <many-to-one name="page" property-ref="pageId" not-null="true" access="field">
-            <column name="reference" />
-            <column name="terminal" />
-        </many-to-one>
-        <property name="title" type="string" length="255" index="PAGE_TITLE" access="field" />
-        <property name="locale" type="string" index="PAGE_LOCALE" length="5" access="field" />
-        <property name="defaultLocale" type="string" index="PAGE_DEFAULT_LOCALE" length="5" access="field" />
-    </class>
-
-    <!--                         -->
-    <!-- Nested Spaces Hierarchy -->
-    <!--                         -->
-
-    <!-- This entity is used to represent the Nested Spaces hierarchy, which we don't use in practice 
-        (we normally use the Nested Pages hierarchy instead) but the Document Tree has an option to display it 
-        so we keep this entity for backward compatibility. Even though the page and the space entities are distinct 
-        in this hierarchy, a space can have both page and space children so we still need to query them together 
-        in order to support sort and pagination. -->
-    <class name="com.xpn.xwiki.internal.model.XWikiPageOrSpace" mutable="false">
-        <subselect><![CDATA[
-            select XWS_REFERENCE as reference, false as terminal, XWS_NAME as name,
-                   XWS_PARENT as parent, null as parentDoc, XWS_HIDDEN as hidden
-                from xwikispace
-            union
-            select XWD_FULLNAME as reference, true as terminal, XWD_NAME as name,
-                   XWD_WEB as parent, XWD_PARENT as parentDoc, XWD_HIDDEN as hidden
-                from xwikidoc
-                where XWD_TRANSLATION = 0
-        ]]></subselect>
-        <synchronize table="xwikidoc" />
-        <synchronize table="xwikispace" />
-        <id column="id" type="long" unsaved-value="undefined" />
-        <properties name="pageId">
-            <property name="reference" type="string" length="255" index="PAGE_REFERENCE" not-null="true" access="field" />
-            <property name="terminal" type="boolean" length="255" index="PAGE_TERMINAL" not-null="true" access="field" />
-        </properties>
-        <property name="name" type="string" length="255" index="PAGE_NAME" not-null="true" access="field" />
-        <property name="parent" type="string" length="255" index="PAGE_PARENT" access="field" />
-        <!-- This is needed in order to implement the deprecated Parent-Child hierarchy over Nested Spaces. 
-            Again, we keep it for backward compatibility because initially the tree view from the Page Index was 
-            displaying the Parent-Child hierarchy with pages grouped by spaces (not the pure Parent-Child hierarchy). -->
-        <property name="parentDoc" type="string" length="255" index="PAGE_PARENT_DOC" access="field" />
-        <property name="hidden" type="boolean" length="255" index="PAGE_HIDDEN" not-null="true" access="field" />
-        <set name="translations" lazy="true" cascade="none" access="field">
-            <key property-ref="pageId">
-                <column name="reference" />
-                <column name="terminal" />
-            </key>
-            <one-to-many class="com.xpn.xwiki.internal.model.XWikiPageOrSpaceTranslation" />
-        </set>
-    </class>
-
-    <!-- The entity that represents the page translations in the Nested Spaces hierarchy. This is needed 
-        in order to be able to sort the children of a space by their localized title. -->
-    <class name="com.xpn.xwiki.internal.model.XWikiPageOrSpaceTranslation" mutable="false">
-        <subselect><![CDATA[
-            select XWD_FULLNAME as reference, true as terminal, nullif(XWD_TITLE, '') as title,
-                   XWD_LANGUAGE as locale, XWD_DEFAULT_LANGUAGE as defaultLocale
-                from xwikidoc
-        ]]></subselect>
-        <synchronize table="xwikidoc" />
-        <id column="id" type="long" unsaved-value="undefined" />
-        <many-to-one name="page" property-ref="pageId" not-null="true" access="field">
-            <column name="reference" />
-            <column name="terminal" />
-        </many-to-one>
-        <property name="title" type="string" length="255" index="PAGE_TITLE" access="field" />
-        <property name="locale" type="string" index="PAGE_LOCALE" length="5" access="field" />
-        <property name="defaultLocale" type="string" index="PAGE_DEFAULT_LOCALE" length="5" access="field" />
-    </class>
 </hibernate-mapping>
-- 
GitLab