Hi,
i have a question concerning the usage of HQL with Entities in Nhibernate.
So first i have this hbm.xml File (ArticleItem and Articlegroup are important)
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="Model.BO" namespace="Model.BO">
<class name="Model.BO.MasterData.ArticleItem, Model.BO" table="ARTICLES" lazy="true" dynamic-update="true"
entity-name="Article" polymorphism="explicit">
<id name="Articleid" column="ARTICLEID" type="int" unsaved-value="0">
<generator class="native" >
<param name="sequence">gen_pk_Articles</param>
</generator>
</id>
<property name="Articlenumber" column="ARTICLENUMBER" type="string" length="18" not-null="false"/>
<many-to-one name="SubSupplier" column="SUBSUPPLIERID" class="Model.BO.MasterData.SubsupplierItem, Model.BO" cascade="none" not-null="false"/>
<property name="Searchword" column="SEARCHWORD" type="string" length="30" not-null="false"/>
<property name="Remark" column="REMARK" type="string" length="1000" not-null="true"/>
<property name="Packagesellmu" column="PACKAGESELLMU" type="string" length="20" not-null="false"/>
<property name="Packagedeliverymu" column="PACKAGEDELIVERYMU" type="string" length="20" not-null="false"/>
<property name="KeepArticleEarnings" column="KEEPARTICLEEARNINGS" type="short" not-null="false"/>
<many-to-one name="Articleearning" column="ARTICLEEARNINGID"
class="Model.BO.MasterData.EarningItem, Model.BO"
entity-name="ArticleEarnings"
cascade="save-update"
not-null="false"
fetch="join"
/>
<many-to-one name="Salaryearning" column="SALARYEARNINGSID"
class="Model.BO.MasterData.EarningItem, Model.BO"
entity-name="SalaryEarnings"
cascade="save-update"
not-null="false"
fetch="join"
/>
<many-to-one name="Overallearning" column="OVERALLEARNINGID"
class="Model.BO.MasterData.EarningItem, Model.BO"
entity-name="ArticleOverallEarnings"
cascade="save-update"
not-null="false"
fetch="join"
/>
<many-to-one name="Salarygroup" column="SALARYGROUPID" class="Model.BO.MasterData.SalarygroupItem, Model.BO" cascade="none" not-null="false"/>
<property name="SimilarArticleId1" column="SIMILAR1ARTICLEID" type="int" not-null="false"/>
<property name="SimilarArticleId2" column="SIMILAR2ARTICLEID" type="int" not-null="false"/>
<many-to-one name="TaxKeyItem" column="TAXKEYID" class="Model.BO.Options.TaxkeyItem, Model.BO" cascade="none" not-null="false"/>
<many-to-one name="Revenue" column="REVENUEID" class="Model.BO.MasterData.RevenueItem, Model.BO" cascade="none" not-null="false"/>
<many-to-one name="Costcenter" column="COSTCENTERID" class="Model.BO.MasterData.CostcenterItem, Model.BO" cascade="none" not-null="false"/>
<many-to-one name="Commissiongroup" column="COMMISSIONGROUPID" class="Model.BO.MasterData.Tables.CommissionGroupsItem, Model.BO" cascade="none" not-null="false"/>
<many-to-one name="Articlegroup" column="ARTICLEGROUPID" class="Model.BO.MasterData.ArticleGroupItem, Model.BO" cascade="none" not-null="false"/>
<property name="Orderarticle" column="ORDERARTICLE" type="short" not-null="false"/>
<property name="Administersserialnumber" column="ADMINISTERSSERIALNUMBER" type="short" not-null="false"/>
<property name="Provisionarticle" column="PROVISIONARTICLE" type="short" not-null="false"/>
<property name="Ean_nr" column="EAN_NR" type="string" length="50" not-null="false"/>
<property name="Ordernr" column="ORDERNR" type="string" length="50" not-null="false"/>
<property name="Catalogside" column="CATALOGSIDE" type="string" length="50" not-null="false"/>
<many-to-one name="Maingoodsgroup" column="MAINGOODSGROUPID" class="Model.BO.MasterData.Tables.MaingoodsgroupItem, Model.BO" cascade="none" not-null="false"/>
<many-to-one name="Goodsgroup" column="GOODSGROUPID" class="Model.BO.MasterData.Tables.GoodsgroupItem, Model.BO" cascade="none" not-null="false"/>
<many-to-one name="Discountgroup" column="DISCOUNTGROUPID" class="Model.BO.MasterData.Tables.DiscountgroupItem, Model.BO" cascade="none" not-null="false"/>
<property name="Summarytext" column="SUMMARYTEXT" type="string" length="1000" not-null="false"/>
<property name="Rtftext" column="RTFTEXT" type="BinaryBlob" not-null="false" lazy="true"/>
<property name="Modifydate" column="MODIFYDATE" type="DateTime" not-null="false"/>
<property name="Modifytime" column="MODIFYTIME" type="DateTime" not-null="false"/>
<many-to-one name="ModifyUser" column="MODIFYUSERID" class="Model.BO.Security.UserItem, Model.BO" cascade="none" not-null="false" fetch="join"/>
<property name="Activeuserid" column="ACTIVEUSERID" type="int" not-null="false"/>
<property name="IsFavorite" column="ISFAVORITE" type="short" not-null="true"/>
<property name="ListPrice" column="LISTPRICE" type="decimal" scale="18" precision="9" not-null="false"/>
<property name="Articleprice" column="ARTICLEPRICE" type="decimal" scale="18" precision="9" not-null="false"/>
<property name="Netprice" column="NETPRICE" type="decimal" scale="18" precision="9" not-null="false"/>
<property name="Salarybaseprice" column="SALARYBASEPRICE" type="decimal" scale="18" precision="9" not-null="false"/>
<property name="SalaryTime" column="SALARYTIME" type="decimal" scale="18" precision="9" not-null="false"/>
<property name="Discount" column="DISCOUNT" type="decimal" scale="18" precision="9" not-null="false"/>
<property name="Packagedeliveryquantity" column="PACKAGEDELIVERYQUANTITY" type="decimal" scale="18" precision="9" not-null="false"/>
<property name="Articlepriceperunit" column="ARTICLEPRICEPERUNIT" type="decimal" scale="18" precision="9" not-null="false"/>
<property name="ConversionFactor" column="CONVERSIONFACTOR" type="decimal" scale="18" precision="9" not-null="false"/>
<property name="Rtftextdata" column="RTFTEXTDATA" type="string" length="5000" not-null="false"/>
<bag name="Pictures" inverse="true" lazy="true" cascade="all">
<key column="ID" />
<one-to-many class="Model.BO.MasterData.PictureArticleItem, Model.BO" />
</bag>
<bag name="RawMaterials" inverse="true" lazy="true" cascade="none">
<key column="ARTICLEID" />
<one-to-many class="Model.BO.MasterData.Articlesm2mrawmaterialItem, Model.BO" />
</bag>
</class>
<class name="Model.BO.MasterData.ArticleItem, Model.BO" table="ACTIVITYARTICLE" lazy="true" dynamic-update="true"
entity-name="Activity_Article" polymorphism="explicit">
<!--polymorphism="explicit" sonst wird HQL alle Instance verwenden!-->
<id name="ActivityArticleId" column="ACTIVITYARTICLEID" type="int" unsaved-value="null">
<generator class="native" >
<param name="sequence">gen_pk_ActivityArticle</param>
</generator>
</id>
<!--ID of orginal article-->
<property name="Articleid" column="ARTICLEID" type="int" not-null="false"/>
<property name="Remark" column="REMARK" type="string" length="1000" not-null="true"/>
<property name="GenQuantity" column="QUANTITY" type="decimal" scale="18" precision="3" not-null="false"/>
<property name="Packagesellmu" column="PACKAGESELLMU" type="string" length="20" not-null="false"/>
<property name="Ismarkposition" column="ISMARKPOSITION" type="short" not-null="false"/>
<property name="Articlepriceperunit" column="ARTICLEPRICEPERUNIT" type="decimal" scale="18" precision="2" not-null="false"/>
<property name="Earningpercentage" column="EARNINGPERCENTAGE" type="decimal" scale="18" precision="2" not-null="false"/>
<property name="Earningprice" column="EARNINGPRICE" type="decimal" scale="18" precision="2" not-null="false"/>
<property name="Salarybaseprice" column="SALARYBASEPRICE" type="decimal" scale="18" precision="2" not-null="false"/>
<property name="Salaryfinalprice" column="SALARYFINALPRICE" type="decimal" scale="18" precision="2" not-null="false"/>
<property name="SalaryTime" column="SALARYTIME" type="decimal" scale="18" precision="2" not-null="false"/>
<many-to-one name="Salarygroup" column="SALARYGROUPID" class="Model.BO.MasterData.SalarygroupItem, Model.BO" cascade="none" not-null="false"/>
<many-to-one name="SubSupplier" column="SUBSUPPLIERID" class="Model.BO.MasterData.SubsupplierItem, Model.BO" cascade="none" not-null="false"/>
<bag name="RawMaterials" inverse="true" lazy="true" cascade="none">
<key column="ACTARTICLEID" />
<one-to-many class="Model.BO.MasterData.Articlesm2mrawmaterialItem, Model.BO" />
</bag>
</class>
</hibernate-mapping>
Then i try a simple HQL Query:
Code:
string HQL = "update Article a set a.IsFavorite = 0 where a.IsFavorite = 1 and a.Articlegroup.Articlegroupid = :ID";
IQuery iquery = _session.CreateQuery(HQL);
iquery.SetInt32("ID", articleGrp.Articlegroupid);
Unfortunately i always get the following Exception:
Quote:
System.ArgumentException: Parameter ID does not exist as a named parameter in [update Article a set a.IsFavorite = 0 where a.IsFavorite = 1 and a.Articlegroup.Articlegroupid = :ID]
I've been searching the web now for a while but i can't really find the answer to this problem.
Without the different Entities the HQL query was working fine, but now i had to implement several Entities and i can't get the query to work.
Maybe someone can give me a hint what i'm doing wrong here.
Thanks in advance.