For example a Employee->User association
<class name="Employee, MyApp" table="Employee" where="inactive=0" >
<many-to-one name="User" class="User, MyApp"
column="UserId" unique="true" not-null="false" >
<class name="User, MyApp" table="Users" where="inactive=0" >
Will generate SQL:
SELECT... FROM Employee this LEFT OUTER JOIN Users user1_ ON this.UserId=user1_.id WHERE this.inactive=0
As you see the "user1_.deleted=0" would not be genetated and User objects will be retrived ignoring the "inactive" flag on Users table. Similar behaviour with <bag>, <one-to-one> and others.
This feature is important for us since we work mostly with legacy data and do not have the luxury of designing our own databases.
I am NHibernate user and I have NHibernate request submited - http://jira.nhibernate.org/browse/NH-467 ; however Sergey Koshcheyev would not implement this in NHibernate unless Hibernate implements it 1st, which is quite understandable.
Also, per Gavin :
"The where clause is not used at all during association navigation. I suspect you might be able to argue that it should be used for navigating many-to-many associations. If you think so, sibmit a feature request to JIRA and I'll give it some thought" (see http://forum.hibernate.org/viewtopic.php?t=189 ).
Actually, I think I am ready to argue that top-level class definition clauses should be used in any type of object instantiation. Would it be possible to consider this implementation?
All versions and platforms