HQL:替换元素()

时间:2015-01-16 07:53:15

标签: database hibernate nhibernate replace hql

我有以下HQL查询:

from Paperboy as paperboy where replace(replace(paperboy._mobile, ' ', ''), '/', '') = :nr or replace(replace(paperboy._phone, ' ', ''), '/', '') = :nr or :nr in elements(paperboy._additionalPhoneNumbers)

现在的问题是,我还必须替换_additionalPhoneNumbers中的空格和斜杠。这可以通过HQL实现吗?

我尝试过像

这样的事情

from Paperboy as paperboy where replace(replace(paperboy._mobile, ' ', ''), '/', '') = :nr or replace(replace(paperboy._phone, ' ', ''), '/', '') = :nr or :nr in elements(replace(replace(paperboy._additionalPhoneNumbers, ' ', ''), '/', ''))

但这引发了异常。 Paperboy的映射是这样的:

<class name="Paperboy"
     table="tblPaperboy"
     lazy="false">
   <id name="_key"
    column="Id"
    access="field" >
      <generator class="assigned"/>
   </id>
   <property name ="_businessId" column="BusinessId" access="field" />
   <many-to-one name="_agency" class="Agency" access="field" column="AgencyKey" />
   <property name ="_lastname" column="Lastname" access ="field" />
   <property name ="_firstname" column="Firstname" access ="field" />
   <property name ="_phone" column="Phone" access ="field" />
   <property name ="_mobile" column="Mobile" access ="field" />

   <bag name="_additionalPhoneNumbers"
     access="field"
     fetch="subselect"
     lazy="false"
     table="tblPaperboyAdditionalPhoneNumbers">
     <key column="PaperboyId"/>
     <element column="PhoneNumber"
           type="string"/>
   </bag>
</class>

1 个答案:

答案 0 :(得分:0)

这可能有效

select
  paperboy
from
  Paperboy as paperboy left join paperboy._additionalPhoneNumbers number
where
  replace(replace(paperboy._mobile, ' ', ''), '/', '') = :nr or
  replace(replace(paperboy._phone, ' ', ''), '/', '') = :nr or
  replace(replace(number, ' ', ''), '/', '') = :nr