persistence@glassfish.java.net

Re: case insensitive

From: Michael Bouschen <mbo.tech_at_spree.de>
Date: Mon, 14 Jan 2008 21:26:41 +0100

Hi,

what Gordon proposed works when using native SQL queries in JPA.
Unfortunately, the Java Persistence query language only supports string
literals and input parameters as pattern value following the keyword
LIKE, so using the UPPER function is not supported here. But you can use
the following WHERE clause:
  WHERE UPPER(c.name) LIKE :name
and then pass the upper case value as actual parameter value:
  query.setParameter("name", string.toUpperCase());

Regards Michael

> You could convert your query to : WHERE UPPER(c.name) LIKE UPPER(?1)
>
> --Gordon
>
> -----Original Message-----
> *From:* TianMing Pan [mailto:Tpan_at_agilitylogistics.com]
> *Sent:* Monday, January 14, 2008 6:16 AM
> *To:* persistence_at_glassfish.dev.java.net
> *Subject:* case insensitive
>
> Hi,
> When I use the JPA, I am confuse about its query for how to make
> it case insensitive.
> For exampe, if I search in the db as "c.name like ?1" and
> setParameter 1
> as "china", then
> the result will not include the "China". So could you tell me how to
> make the query case
> insensitive? Thanks a lot.
>
> Rds
>
>
> All Business is handled subject to our General Trading Conditions.
> A copy can be made available upon request.
>


-- 
Tech_at_Spree Engineering GmbH  Tel.: +49/(0)30/235 520-33
Buelowstr. 66                Fax.: +49/(0)30/217 520-12
10783 Berlin                 mailto:mbo.tech_at_spree.de 
 
Geschaeftsfuehrung: Martin Weber
Sitz Berlin, Amtsgericht Charlottenburg, HRB 564 52