-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Loading relations does not respect where clause
PostPosted: Tue Dec 11, 2007 4:50 am 
Newbie

Joined: Tue Dec 11, 2007 4:17 am
Posts: 3
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.