D
D
dikkini2014-05-04 20:11:27
Java
dikkini, 2014-05-04 20:11:27

Hibernate, ilike, Russian letters?

Hello. There is the following code:

Restrictions.ilike("lastName", lastName, MatchMode.ANYWHERE);

The problem is the following.
Search word: Ivanov
Search string: i, iv, iva, ivan, ivanov
Result: search word not found
Search string: v, a, n, o, v, va, an, ano, nov, anov, van, vano , vanov, ov
Result: the search word was found.
Search word: ivanov
Search string: any
Result: search word found.
Search word: Malkovich
Search string: m, ma, mal, malk, malko, malkov, malkovi, malkovic, malkovich
Result: search word found.
It turns out that if I look for a Russian word that starts with a capital letter, and I look for it starting with the first letter, it is not found.
Even if I replace the MethodMatch.ANYWHERE search method with MethodMatch.START, it will not start to be found.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
NightFantom, 2014-08-16
@dikkini

If I understand correctly, then you are not looking for it. Restrictions.like("lastName", "%"+ WORD +"%") In SQL, the like command looks for similarity to a pattern. Masks are allowed in the template. % means any sequence of characters.

V
Vladimir Smirnov, 2014-05-11
@bobzer

I would advise you to start by running all queries without Hibernate, but directly to the database and look at the results. Or read the doc/google about how your DBMS works with character case. For example, Oracle obliges you to specify the same case in the condition as in the database (otherwise it will not find it), and MySQL allows you not to think about it. It is most reliable to bring the registers of characters to a certain predefined state before saving the data in the database (for example, all characters to upper case), and later, when a condition is imposed on the selection, also bring the case of the searched string. If there is already garbage in the database (who both entered it and saved it), then you can create indexes in the desired register, i.e. in the field of the table at random, and in the index on this field everything is in UPPER. Or do update table set field = UPPER(field). In general, first look at the DBMS, and only then at Hibernate ...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question