Return-Path: X-Original-To: apmail-openjpa-users-archive@minotaur.apache.org Delivered-To: apmail-openjpa-users-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 395834336 for ; Mon, 9 May 2011 15:58:35 +0000 (UTC) Received: (qmail 18988 invoked by uid 500); 9 May 2011 15:58:35 -0000 Delivered-To: apmail-openjpa-users-archive@openjpa.apache.org Received: (qmail 18955 invoked by uid 500); 9 May 2011 15:58:35 -0000 Mailing-List: contact users-help@openjpa.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@openjpa.apache.org Delivered-To: mailing list users@openjpa.apache.org Received: (qmail 18946 invoked by uid 99); 9 May 2011 15:58:35 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 09 May 2011 15:58:35 +0000 X-ASF-Spam-Status: No, hits=2.2 required=5.0 tests=HTML_MESSAGE,RCVD_IN_DNSWL_NONE,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: local policy) Received: from [194.109.24.26] (HELO smtp-vbr6.xs4all.nl) (194.109.24.26) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 09 May 2011 15:58:27 +0000 Received: from remote.huizemolenaar.nl (D57D0452.static.ziggozakelijk.nl [213.125.4.82]) (authenticated bits=0) by smtp-vbr6.xs4all.nl (8.13.8/8.13.8) with ESMTP id p49Fw4XN013322 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=FAIL) for ; Mon, 9 May 2011 17:58:05 +0200 (CEST) (envelope-from henno@huizemolenaar.nl) Received: from HMS.hm.local ([fe80::6051:4a91:4c0d:d963]) by HMS.hm.local ([fe80::6051:4a91:4c0d:d963%10]) with mapi; Mon, 9 May 2011 17:58:03 +0200 From: Henno Vermeulen To: "'users@openjpa.apache.org'" Date: Mon, 9 May 2011 17:58:02 +0200 Subject: query that uses String REPLACE function Thread-Topic: query that uses String REPLACE function Thread-Index: AcwOYGMgzPdVgQSNRDyM37CSjpLa8w== Message-ID: <1C448C478A6B4743AF19DBC3C3DCE13201BD1D83CC40@HMS.hm.local> Accept-Language: nl-NL Content-Language: nl-NL X-MS-Has-Attach: X-MS-TNEF-Correlator: acceptlanguage: nl-NL Content-Type: multipart/alternative; boundary="_000_1C448C478A6B4743AF19DBC3C3DCE13201BD1D83CC40HMShmlocal_" MIME-Version: 1.0 X-Virus-Scanned: by XS4ALL Virus Scanner --_000_1C448C478A6B4743AF19DBC3C3DCE13201BD1D83CC40HMShmlocal_ Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable I have a Contact entity with a telephone number field of type String. I wis= h to query for Contacts that have a given telephone number. For this compar= ison to succeed I have to replace some characters in the stored field ("+" = by 00 and "-" and space by an empty string). With a sql server native query= I can do something like this: SELECT * FROM Contact WHERE REPLACE(REPLACE(REPLACE(telephone,' ',''), '+', 00), '-', '') LIKE @phoneNu= mber What would be my best option to do this with JPA? I was thinking of one of these possibilities: - Criteria API. Put the three REPLACE's in a user defined function= . If this is possible, call this UDF with the criteria API. - Use a native query - Map an entity to a database view that has a telephone column wit= h the characters replaced - Always store the telephone number with the characters already re= placed But the first three feel much too complicated for such a simple problem. Th= e last one is a bit too strict for my taste but I think it is the best opti= on unless anyone knows a better solution that I can use. Regards, Henno Vermeulen Huize Molenaar --_000_1C448C478A6B4743AF19DBC3C3DCE13201BD1D83CC40HMShmlocal_--