1

I'm currently doing:

criteria = new Criteria().andOperator(where("car.color").is(car_color),
                                      where("car_size").is(car_size))

How to make this search works for both car_color = BLUE and car_color = blue ?


Update:

This partially works:

where("car.color").regex(car_color, "i"),

But then all values below would be updated:

BLUE
BBLUE
blue
bluee

And I want to update only what is matched in the car_color variable(case insensitive).

Jens Schauder
  • 77,657
  • 34
  • 181
  • 348
jimmy
  • 457
  • 5
  • 20
  • Don`t know your API, but dont you have a select uppercase to compare with equals uppercase criteria? like ```SELECT * FROM cars where UPPER('car.color') = 'BLUE'``` – Marcos Vasconcelos Nov 04 '21 at 01:00
  • Thanks for the suggestion. I already have some entries in the database with upper/lower case that can't be updated, so that won't work. – jimmy Nov 04 '21 at 01:20
  • The idea of the select upper is to change the result of the query not to update the database – Marcos Vasconcelos Nov 04 '21 at 16:34

2 Answers2

0

I think what you want is to pre process your string to be all caps or all lowercase. In java that's done like:

car_color.toLowerCase() or car_color.toUpperCase()

Then you know its all in caps or all in lowercase, and can compare the string appropriately

bartius
  • 202
  • 2
  • 7
  • Your assumption is wrong, but thanks for the suggestion. I already have some entries in the database with upper/lower case that can't be updated. – jimmy Nov 04 '21 at 00:39
  • 1
    ah I see, sorry I couldn't have been of more help. Im not super familiar with the Criteria API, but maybe this previous post will help? https://stackoverflow.com/questions/4580285/jpa2-case-insensitive-like-matching-anywhere – bartius Nov 04 '21 at 01:01
0

The solution for my problem is:

criteria = new Criteria().andOperator(where("car.color").regex("^" + car_color+ "$", "i"),
                                      where("car_size").is(car_size))
jimmy
  • 457
  • 5
  • 20