本文介绍了HQL:replace on elements()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下HQL查询:



来自Paperboy作为paperboy
其中
replace ._mobile,'',''),'/','')=:nr或replace(replace(paperboy._phone,'',''),'/','')=:nr或
:元素中的nr(paperboy._additionalPhoneNumbers)



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



我试过像Paperboy的




其中
替换(替换(paperboy._mobile,'',''),'/','')=:nr或替换(paperboy._phone,'',' '/',''))
: c $ c>



但这会抛出异常。纸工的映射如下:

 < class name =Paperboy
table =tblPaperboy
lazy =false>
< id name =_ key
column =Id
access =field>
< generator class =assigned/>
< / id>
< property name =_ businessIdcolumn =BusinessIdaccess =field/>
< many-to-one name =_ agencyclass =Agencyaccess =fieldcolumn =AgencyKey/>
< property name =_ lastnamecolumn =Lastnameaccess =field/>
< property name =_ firstnamecolumn =Firstnameaccess =field/>
< property name =_ phonecolumn =Phoneaccess =field/>
< property name =_ mobilecolumn =Mobileaccess =field/>

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


解决方案

这可能有用

  select 
paperboy

纸工作为paperboy left join paperboy._additionalPhoneNumbers数字
其中
(replace(paperboy._phone,'',''),'/','')=:nr或
replace )=:nr或
replace(replace(number,'',''),'/','')=:nr

I have the following HQL-Query:

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

Now the problem is, that I also have to replace spaces and slashs in the _additionalPhoneNumbers. Is this possible via HQL?

I tried things like

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

but this throws an exception. Mapping of Paperboy is like this:

<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>
解决方案

this might work

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

这篇关于HQL:replace on elements()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-14 05:11