Hello,
in our architecture every table has some system columns such as Validity. We dont really delete the rows, we just set validity to 0.
In XML mapping files for all entities we have a WHERE clause, which specifies that only rows with "Validity = 1" should be loaded from the database. However when we use relations to navigate from entity to its related entity collection, all childrens are loaded (even those with Validity = 0).
Example (pseudo) code:
TimeZone tz = TimeZone.LoadByIdTimeZone(1);
List<TimeZoneItem> items = tz.TimeZoneItems;
Now items contains all items with idTimeZone = 1 no matter if validity is 0 or 1. I think this behaviour is incorrect.
Hibernate version: 1.2.0.400
Mapping documents:
<?xml version="1.0" encoding="UTF-8"?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="DataLayer.TimeZone, DataLayer" table="[TimeZone]" where="Validity = 1" mutable="true">
<id access="nosetter.camelcase-underscore" name="IdTimeZone" column="idTimeZone">
<generator class="identity" />
</id>
<property access="nosetter.camelcase-underscore" name="TimeZoneName" column="TimeZoneName" />
<property access="nosetter.camelcase-underscore" name="IsSystem" column="IsSystem" />
<property access="nosetter.camelcase-underscore" name="ChangeMaker" column="ChangeMaker" />
<property access="nosetter.camelcase-underscore" name="Validity" column="Validity" />
<bag name="AccessRights" generic="true">
<key column="idTimeZone" />
<one-to-many class="DataLayer.AccessRight, DataLayer" />
</bag>
<bag name="TimeZoneItems" generic="true">
<key column="idTimeZone" />
<one-to-many class="DataLayer.TimeZoneItem, DataLayer" />
</bag>
</class>
</hibernate-mapping>
<?xml version="1.0" encoding="UTF-8"?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="DataLayer.TimeZoneItem, DataLayer" table="[TimeZoneItem]" where="Validity = 1" mutable="true">
<id access="nosetter.camelcase-underscore" name="IdTimeZoneItem" column="idTimeZoneItem">
<generator class="identity" />
</id>
<many-to-one name="TimeZone" column="idTimeZone" class="DataLayer.TimeZone, DataLayer" />
<property access="nosetter.camelcase-underscore" name="DayMask" column="DayMask" />
<property access="nosetter.camelcase-underscore" name="TimeFrom" column="TimeFrom" />
<property access="nosetter.camelcase-underscore" name="TimeTo" column="TimeTo" />
<property access="nosetter.camelcase-underscore" name="ChangeMaker" column="ChangeMaker" />
<property access="nosetter.camelcase-underscore" name="Validity" column="Validity" />
</class>
</hibernate-mapping>
Name and version of the database you are using: SQL Server 2005
Any help appreciated
Thank you
|