-->
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.  [ 4 posts ] 
Author Message
 Post subject: Trouble with Entities in HQL Query
PostPosted: Wed May 04, 2011 9:59 am 
Newbie

Joined: Wed May 04, 2011 9:42 am
Posts: 1
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.


Top
 Profile  
 
 Post subject: Re: Trouble with Entities in HQL Query
PostPosted: Fri May 06, 2011 3:53 am 
Newbie

Joined: Thu May 05, 2011 1:38 am
Posts: 7
Shortly:
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);

Throws exception if we use different mapping (through entity-name="..")for the same class ("ArticleItem")
Code:
<class name="ArticleItem" ... entity-name="Article" polymorphism="explicit">
<class name="ArticleItem" ... entity-name="Article2" polymorphism="explicit">

The same code was working without problems as we had only one mapping for "ArticleItem":
Code:
<class name="ArticleItem" ... polymorphism="explicit">

Code:
string HQL = "update ArticleItem a set a.IsFavorite = 0 where a.IsFavorite = 1 and a.Articlegroup.Articlegroupid = :ID";
IQuery iquery = _session.CreateQuery(HQL);
iquery.SetInt32("ID", articleGrp.Articlegroupid);


PS. NHibernate 3.1.0 GA

Has anyone any idea?


Top
 Profile  
 
 Post subject: Re: Trouble with Entities in HQL Query
PostPosted: Tue May 10, 2011 4:23 am 
Newbie

Joined: Thu May 05, 2011 1:38 am
Posts: 7
Created ticket on JIRA NH-2697: http://216.121.112.228/browse/NH-2697


Top
 Profile  
 
 Post subject: Re: Trouble with Entities in HQL Query
PostPosted: Thu May 12, 2011 7:51 am 
Newbie

Joined: Thu May 12, 2011 7:49 am
Posts: 1
The males are called Feng and the females Huang. In modern times, however, such a distinction of gender is often no longer made and the Feng and Huang are blurred into a single feminine entity so that the bird can be paired with the Chinese dragon, which has male connotations.












phoenix bands


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

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.