I am migrating a project from hibernate 4 to 5.6x. We have user-defined schemas in the hbm mapping files and those auxiliary database schemas should be exported in proper sequence order.
If you see the below one, first it would drop the IND table and next it creates a view with the same name.
<hibernate-mapping package="com.tpk.or">
<!-- The parent class, whose table will be dropped and replaced by a view. -->
<class name="INDCount" entity-name="INDCount" table="IND" polymorphism="explicit">
&orProperties;
<component name="statsKey" class="com.tpk.or.StatsKey" access="field"
lazy="false">
<many-to-one name="dateComp" column="sod"
class="com.tpk.or.DateComponents"
not-null="true" foreign-key="ma_sod_fk" lazy="false"/>
<many-to-one name="timeComp" column="mod"
class="com.tpk.or.TimeComp"
not-null="true" foreign-key="ma_tod_fk" lazy="false"/>
<property name="granularity" type="int"
access="com.tpk.or.dao.PropAccessor" not-null="true"/>
</component>
</class>
<database-object>
<create>DROP TABLE IND</create>
<drop></drop>
<dialect-scope name="com.tpk.sqlServerDialect.SQLMappingFix"/>
</database-object>
<database-object>
<create>
CREATE VIEW IND
WITH SCHEMABINDING
AS
SELECT id, sod, mod, 0 as granularity,
COMPONENT_ID, APPLICATION_ID, BRIDGED
FROM dbo.IND_5MIN
UNION ALL
SELECT id, sod, mod, 6,
COMPONENT_ID, APPLICATION_ID, BRIDGED
FROM dbo.IND_30MIN
</create>
<drop>DROP VIEW IND</drop>
<dialect-scope name="com.tpk.sqlServerDialect.SQLMappingFix"/>
</database-object>
</hibernate-mapping>
In Hib4 Schemaexport class always maintains the order while generating the schemas but in Hib5 auxiliary DB schemas not generating in sequence order.
In our case, create view generate before the drop table schema. (refer below)
CREATE TABLE IND ****
GO
CREATE VIEW IND
WITH SCHEMABINDING
AS
SELECT id, sod, mod, 0 as granularity,
COMPONENT_ID, APPLICATION_ID, BRIDGED
FROM dbo.IND_5MIN
UNION ALL
SELECT id, sod, mod, 6,
COMPONENT_ID, APPLICATION_ID, BRIDGED
FROM dbo.IND_30MIN
GO
DROP TABLE IND
After debugging the code, I noticed that the auxiliary DB object stores in the hashmap in the Hib5 but in the previous version it stores in ArrayList that’s why the Hib5 auxiliary db object not maintaining the order while exporting.
I don’t see any documentation about this change. Is there any option to maintain the order ?
How to fix/handle this problem ?