using NHibernate 1.2.0GA with SQLServer2005.
Hi,
at first an extract of my mappings:
Code:
<?xml version="1.0"?>
<hibernate-mapping xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="urn:nhibernate-mapping-2.2">
<class name="Moveo.Care.Core.BLL.User, Moveo.Care.Core.BLL" table="gpd_user" where="([__Deleted]=0 or [__Deleted] is null)">
<id name="ID" column="usr_id" type="Int32">
<generator class="increment" />
</id>
<property name="UserName" column="usr_uname" length="20" not-null="true" />
<property name="Password" column="usr_pwd" length="254" />
<property name="Email" column="usr_email" length="254" />
<property name="Description" column="usr_desc" length="254" />
<property name="State" column="usr_state" not-null="true" />
<property name="FailedLogins" column="usr_failed_logins" not-null="true" />
<property name="LastLogin" column="usr_last_login" />
<property name="__Create_Date" column="__Create_Date" />
<property name="__LastModified_Date" column="__LastModified_Date" />
<property name="Moveo.Care.Core.Persistence.IBusinessObject.__Deleted" column="__Deleted" />
<many-to-one name="__Create_User" class="Moveo.Care.Core.BLL.User, Moveo.Care.Core.BLL" column="__Create_User" />
<many-to-one name="__LastModified_User" class="Moveo.Care.Core.BLL.User, Moveo.Care.Core.BLL" column="__LastModified_User" />
<one-to-one name="Contact" class="Moveo.Care.MasterData.Contacts.BLL.Contact, Moveo.Care.MasterData.Contacts.BLL" cascade="none" property-ref="User" />
<bag name="UserGroups" table="gpd_ugrp_ass" lazy="false" cascade="save-update">
<key foreign-key="FK_gpd_ugrp_ass_usr">
<column name="uga_usr" not-null="true" unique-key="UQ_gpd_ugrp_ass_ASS" />
</key>
<many-to-many class="Moveo.Care.Core.BLL.UserGroup, Moveo.Care.Core.BLL" foreign-key="FK_gpd_ugrp_ass_ugrp">
<column name="uga_grp" not-null="true" unique-key="UQ_gpd_ugrp_ass_ASS" />
</many-to-many>
</bag>
<bag name="Privileges" cascade="all" inverse="true">
<key column="prv_usr" foreign-key="FK_gpd_privileges_usr" />
<one-to-many class="Moveo.Care.Core.BLL.Privilege, Moveo.Care.Core.BLL" />
</bag>
</class>
<class name="Moveo.Care.MasterData.Contacts.BLL.Contact, Moveo.Care.MasterData.Contacts.BLL" lazy="true" table="md_contacts" where="([__Deleted]=0 or [__Deleted] is null)" batch-size="25">
<id name="ID" column="con_id" type="Int32">
<generator class="increment" />
</id>
<property name="Remark" type="StringClob" column="con_remark" length="10000" />
<property name="Inactive" column="con_inactive" />
<property name="Number" column="con_number" length="254" not-null="true" />
<property name="BankAccountNr" column="con_acc_bank_nr" length="20" />
<property name="DifferingAcceptor" column="con_differing_acceptor" length="254" />
<property name="TermsOfPayment" type="StringClob" column="con_termsofpayment" length="10000" />
<property name="NetPayer" column="con_net_payer" not-null="true" />
<property name="Discount2" column="con_discount2" />
<property name="__Create_Date" column="__Create_Date" />
<property name="__LastModified_Date" column="__LastModified_Date" />
<property name="Moveo.Care.Core.Persistence.IBusinessObject.__Deleted" column="__Deleted" />
<many-to-one name="User" class="Moveo.Care.Core.BLL.User, Moveo.Care.Core.BLL" column="con_user_id" cascade="none" />
<many-to-one name="GroupStructureMember" class="Moveo.Care.MasterData.Contacts.BLL.IContactGroupStructure, Moveo.Care.MasterData.Contacts.BLL" column="con_grpstruc_id" not-null="true" lazy="false" />
<many-to-one name="Bank" class="Moveo.Care.ControlData.Common.BLL.Bank, Moveo.Care.ControlData.Common.BLL" column="con_bc_id" />
<many-to-one name="__Create_User" class="Moveo.Care.Core.BLL.User, Moveo.Care.Core.BLL" column="__Create_User" />
<many-to-one name="__LastModified_User" class="Moveo.Care.Core.BLL.User, Moveo.Care.Core.BLL" column="__LastModified_User" />
<component name="FullName" class="Moveo.Care.MasterData.Contacts.BLL.Contact+Name, Moveo.Care.MasterData.Contacts.BLL">
<property name="NameAffix" column="con_nax" />
<property name="Name1" column="con_name1" length="254" />
<property name="Name2" column="con_name2" length="254" />
<property name="Title" column="con_title" length="254" />
<property name="Salutation" column="con_sal" />
</component>
<bag name="Addresses" cascade="all-delete-orphan" inverse="true" batch-size="10">
<key column="adr_con_id" foreign-key="FK_md_addresses_con_id" />
<one-to-many class="Moveo.Care.MasterData.Contacts.BLL.Address, Moveo.Care.MasterData.Contacts.BLL" />
</bag>
<bag name="CommunicationEntries" cascade="all-delete-orphan" inverse="true" batch-size="10">
<key column="ce_con_id" />
<one-to-many class="Moveo.Care.MasterData.Contacts.BLL.CommunicationEntry, Moveo.Care.MasterData.Contacts.BLL" />
</bag>
</class>
<joined-subclass name="Moveo.Care.MasterData.Contacts.BLL.DoctorInstitution, Moveo.Care.MasterData.Contacts.BLL" proxy="Moveo.Care.MasterData.Contacts.BLL.DoctorInstitution, Moveo.Care.MasterData.Contacts.BLL" lazy="true" extends="Moveo.Care.MasterData.Contacts.BLL.Contact, Moveo.Care.MasterData.Contacts.BLL" table="md_doctor_institution">
<key column="di_con_id" />
<property name="CPD" column="di_cpd" length="254" />
<property name="Lock" column="di_lock" />
<property name="Remind" column="di_remind" length="254" />
<property name="Vendor" column="di_vendor" length="254" />
<property name="Debitor" column="di_debitor" length="254" />
<property name="CurrencyCode" column="di_currency_code" length="254" />
<property name="TaxID" column="di_tax_id" length="254" />
<property name="PurchaseTaxID" column="di_purchase_tax_id" length="254" />
<property name="SalesTaxLiability" column="di_sales_tax_liability" />
<property name="RemindBalance" column="di_remind_balance" />
<property name="CurrentBalance" column="di_current_balance" />
<property name="LastRemind" column="di_last_remind" />
<property name="LastPayment" column="di_last_payment" />
<property name="LastInvoice" column="di_last_invoice" />
<property name="CollectiveInvoices" column="di_collectiveinvoices" />
<bag name="Prospectives" inverse="true">
<key column="rel_di_id" />
<one-to-many class="Moveo.Care.MasterData.Contacts.BLL.ContactRelation, Moveo.Care.MasterData.Contacts.BLL" />
</bag>
<bag name="CostUnitRelations" cascade="all" inverse="true">
<key column="cur_contact" />
<one-to-many class="Moveo.Care.MasterData.Contacts.BLL.ProspectiveCostUnitRelation, Moveo.Care.MasterData.Contacts.BLL" />
</bag>
<bag name="ContactPersons" cascade="all" inverse="true">
<key column="cp_di_id" />
<one-to-many class="Moveo.Care.MasterData.Contacts.BLL.ContactPerson, Moveo.Care.MasterData.Contacts.BLL" />
</bag>
</joined-subclass>
<joined-subclass name="Moveo.Care.MasterData.Contacts.BLL.Prospective, Moveo.Care.MasterData.Contacts.BLL" proxy="Moveo.Care.MasterData.Contacts.BLL.Prospective, Moveo.Care.MasterData.Contacts.BLL" lazy="true" extends="Moveo.Care.MasterData.Contacts.BLL.Contact, Moveo.Care.MasterData.Contacts.BLL" table="md_resid_prosp">
<key column="rdp_con_id" />
<property name="FamilyStatus" column="rdp_family_status" />
<property name="FamilyStatusDate" column="rdp_family_status_year" />
<property name="WayOfLife" column="rdp_way_of_life" />
<property name="WayOfLifeDate" column="rdp_way_of_life_year" />
<property name="Denomination" column="rdp_denomination" not-null="true" />
<property name="Birthday" column="rdp_birthday" not-null="true" />
<property name="BirthName" column="rdp_birthname" length="254" />
<property name="Birthplace" column="rdp_birthplace" length="80" />
<property name="BirthCountry" column="rdp_birthcountry" />
<property name="Gender" column="rdp_gender" not-null="true" />
<property name="Nationality" column="rdp_nationality" length="60" />
<property name="Citizenship" column="rdp_citizenship1" length="60" />
<property name="Citizenship2" column="rdp_citizenship2" length="60" />
<property name="HandyCapType" column="rdp_handycaptype" not-null="true" />
<property name="HandyCapGrade" column="rdp_handycapgrade" />
<property name="Debtor" column="rdp_debtor" />
<property name="LastInvoice" column="rdp_last_invoice" />
<property name="IsCurrencyManagementIndividually" column="rdp_currency_mgmt_ind" not-null="true" />
<property name="IsCurrencyManagementCollectively" column="rdp_currency_mgmt_coll" not-null="true" />
<property name="Picture" type="Serializable" column="rdp_picture" length="2147483646" />
<property name="Description" column="reslc_description" length="254" />
<one-to-one name="NewResident" class="Moveo.Care.MasterData.Contacts.BLL.Resident, Moveo.Care.MasterData.Contacts.BLL" cascade="none" property-ref="FormerProspective" />
<bag name="Children" cascade="all" inverse="true" batch-size="10">
<key column="chdn_prosp_id" />
<one-to-many class="Moveo.Care.MasterData.Contacts.BLL.Child, Moveo.Care.MasterData.Contacts.BLL" />
</bag>
<bag name="Contacts" cascade="all-delete-orphan" inverse="true" batch-size="10">
<key column="rel_prosp_id" />
<one-to-many class="Moveo.Care.MasterData.Contacts.BLL.ContactRelation, Moveo.Care.MasterData.Contacts.BLL" />
</bag>
<bag name="TherapyGroups" cascade="all-delete-orphan" inverse="true" batch-size="10">
<key column="rel_prosp_id" />
<one-to-many class="Moveo.Care.MasterData.Contacts.BLL.TherapyProspectiveRelation, Moveo.Care.MasterData.Contacts.BLL" />
</bag>
<bag name="CostUnitRelations" cascade="all-delete-orphan" inverse="true" batch-size="10">
<key column="cur_prospective" />
<one-to-many class="Moveo.Care.MasterData.Contacts.BLL.ProspectiveCostUnitRelation, Moveo.Care.MasterData.Contacts.BLL" />
</bag>
<bag name="InfoLibraryHeaders" cascade="save-update" inverse="true" batch-size="10">
<key column="hil_prospective_id" />
<one-to-many class="Moveo.Care.MasterData.CataloguesCare.BLL.Head_InfoLibrary, Moveo.Care.MasterData.CataloguesCare.BLL" />
</bag>
</joined-subclass>
<joined-subclass name="Moveo.Care.MasterData.Contacts.BLL.Resident, Moveo.Care.MasterData.Contacts.BLL" proxy="Moveo.Care.MasterData.Contacts.BLL.Resident, Moveo.Care.MasterData.Contacts.BLL" lazy="true" extends="Moveo.Care.MasterData.Contacts.BLL.Prospective, Moveo.Care.MasterData.Contacts.BLL" table="md_residents">
<key column="rdt_rdi_con_id" />
<property name="IsInPatient">
<column name="rdt_is_in_patient" not-null="false" />
</property>
<property name="UnderDisability">
<column name="rdt_under_disability" not-null="true" sql-type="Integer" />
</property>
<many-to-one name="FormerProspective" class="Moveo.Care.MasterData.Contacts.BLL.Prospective, Moveo.Care.MasterData.Contacts.BLL" column="res_prosp_id" cascade="none" />
<bag name="CurrencyManagementEntries" inverse="true" batch-size="10">
<key column="cme_resident_id" />
<one-to-many class="Moveo.Care.Trans.Care.BLL.CurrencyManagementEntry, Moveo.Care.Trans.Care.BLL" />
</bag>
<bag name="FavoriteEmpRelations" cascade="all" inverse="true" batch-size="10">
<key column="rel_res_id" />
<one-to-many class="Moveo.Care.MasterData.Contacts.BLL.FavoriteEmployeeRelation, Moveo.Care.MasterData.Contacts.BLL" />
</bag>
<bag name="Documents" cascade="all" inverse="true" batch-size="10">
<key column="doc_rdt_id" foreign-key="md_documents_rdt_id" />
<one-to-many class="Moveo.Care.MasterData.Contacts.BLL.Documents, Moveo.Care.MasterData.Contacts.BLL" />
</bag>
<bag name="Belongings" cascade="all" inverse="true" batch-size="10">
<key column="blg_rdt_id" />
<one-to-many class="Moveo.Care.MasterData.Contacts.BLL.BelongingLending, Moveo.Care.MasterData.Contacts.BLL" />
</bag>
<bag name="CurrencyManagementAccountRelations" cascade="all-delete-orphan" inverse="true">
<key column="carr_resident_id" />
<one-to-many class="Moveo.Care.Trans.Care.BLL.CurrencyAccountResidentRelation, Moveo.Care.Trans.Care.BLL" />
</bag>
<bag name="LifeCycles" cascade="all-delete-orphan" inverse="true" batch-size="10" order-by="reslc_nursing_begin asc">
<key column="reslc_res_id" />
<one-to-many class="Moveo.Care.MasterData.Contacts.BLL.ResidentLifeCycle, Moveo.Care.MasterData.Contacts.BLL" />
</bag>
<bag name="AccountingItemRelations" cascade="all-delete-orphan" inverse="true" batch-size="10">
<key column="rair_resident_id" />
<one-to-many class="Moveo.Care.MasterData.Contacts.BLL.ResidentAccountingItemRelation, Moveo.Care.MasterData.Contacts.BLL" />
</bag>
<bag name="TrendDocs" inverse="true" batch-size="10">
<key column="td_con_id" />
<one-to-many class="Moveo.Care.Trans.Care.BLL.TrendDoc, Moveo.Care.Trans.Care.BLL" />
</bag>
</joined-subclass>
...
...
...
</hibernate-mapping>
then here my hql query:
Code:
from User u where u.UserName like :userName
so... and now... the generated SQL:
Code:
SELECT
this_.usr_id as usr1_26_2_,
.......
FROM gpd_user this_
left outer join md_contacts contact2_ on this_.usr_id=contact2_.con_user_id and (contact2_.[__Deleted]=0 or contact2_.[__Deleted] is null)
left outer join md_doctor_institution contact2_1_ on contact2_.con_id=contact2_1_.di_con_id
left outer join md_resid_prosp contact2_2_ on contact2_.con_id=contact2_2_.rdp_con_id
left outer join md_employee contact2_3_ on contact2_.con_id=contact2_3_.emp_con_id
left outer join md_residents contact2_4_ on contact2_.con_id=contact2_4_.rdt_rdi_con_id
left outer join md_contacts_company contact2_5_ on contact2_.con_id=contact2_5_.comp_con_id
left outer join md_residents resident3_ on contact2_.con_id=resident3_.res_prosp_id and (resident3_2_.[__Deleted]=0 or resident3_2_.[__Deleted] is null)
left outer join md_resid_prosp resident3_1_ on resident3_.rdt_rdi_con_id=resident3_1_.rdp_con_id
left outer join md_contacts resident3_2_ on resident3_.rdt_rdi_con_id=resident3_2_.con_id
WHERE (this_.[__Deleted]=0 or this_.[__Deleted] is null) AND lower(this_.usr_uname) like ?
the fault is here:
Code:
left outer join md_residents resident3_ on contact2_.con_id=resident3_.res_prosp_id and (resident3_2_.[__Deleted]=0 or resident3_2_.[__Deleted] is null)
the alias "resident3_2_" is defined lower in the statment in the last left join.... so I get an error from the sqlserver, which says, that he cannot bind the identifier 'resident3_2_.[Deleted]".
When I put the expression:
Code:
and (resident3_2_.[__Deleted]=0 or resident3_2_.[__Deleted] is null)
in the on clause of the last left join, all is fine.
It seems, that nhibernate generates wrong sql here!??
How can I correct that? Is it a bug? Or is the mistake on my side?
I hope someone can help me :-(.
best regards,
ramon