Вопрос

Is there any operator in JPQL equivalent to SQL BINARY?
I googled a lot and find no one mentions it.

Thanks in advance!


For the BINARY operator, here's the description in MySQL site.

The BINARY operator casts the string following it to a binary string. 
This is an easy way to force a column comparison to be done byte by byte 
rather than character by character. This causes the comparison to be case 
sensitive even if the column is not defined as BINARY or BLOB. BINARY also 
causes trailing spaces to be significant.   

mysql> SELECT 'a' = 'A';  
        -> 1  
mysql> SELECT BINARY 'a' = 'A';  
        -> 0  
mysql> SELECT 'a' = 'a ';  
        -> 1  
mysql> SELECT BINARY 'a' = 'a ';  
        -> 0  

BTY, I'm using MySql 5.6.(Though I don't think this problem is related to MySql...)

Это было полезно?

Решение

I still can't find the equivalent operator of BINARY in JPQL.
But there's a work around if you come across this problem :
In JPA, just use em.createNativeQuery() and you may use SQL and thus you can use BINARY operator. Like this:

em.createNativeQuery("SELECT * FROM Student WHERE name=binary'"+ stuName+"'").getResultList();

Just provide those who have the same problem a solution.

Другие советы

As of JPA 2.0 solution mentioned by @nosnhoj is the only solution which works until you want to change the collation of your database or table. I am not sure about JPA 2.1. Thanks for your help.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top