Hi all,
I've recently used JPA function LENGTH (under JBoss 5.1.0 GA) and faced wrong behavior.
The following JPQL statement
Code:
SELECT d.id FROM Depositor d WHERE LENGTH(d.firstName) > :firstNameMinLength
was converted into the following native SQL statement through MySQLDialect
Code:
select depositor0_.id as id24_ from depositor depositor0_ where length(depositor0_.first_name)>?
It is incorrect IMHO because according to the section 4.6.16.1 of the JPA spec
Quote:
The LENGTH function returns the length of the string in characters as an integer.
but according to the MySQL documentation (
http://dev.mysql.com/doc/refman/5.1/en/ ... ion_length)
Quote:
LENGTH(str)
Returns the length of the string str, measured in bytes
In the case of multibyte character encodings (russian chars in UTF-8 in my case) this leads into troubles.
In the right case the LENGTH() JPA function should be mapped onto the CHAR_LENGTH() MySQL function.