2014-01-17 52 views
0

JPQL中是否有任何运算符等同于SQL BINARY
我GOOGLE了很多,发现没有人提到它。什么是JPQL中的BINARY运算符?

在此先感谢!


对于二元运算符,这里是在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,我使用MySQL 5.6。(虽然我不认为这个问题与MySQL有关的做...)

回答

0

我仍然无法找到的BINARY的等效运营 in JPQL
但是,如果遇到此问题,可以采取以下解决方法:
在JPA中,只需使用em.createNativeQuery()即可使用SQL,因此可以使用BINARY运算符。 想要这样:

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

只是提供那些谁有同样的问题的解决方案。

+1

这看起来像一个很大的SQL注入目标! –

0

从@nosnhoj提到的JPA 2.0解决方案是唯一的解决方案,直到您想要更改数据库或表的排序规则为止。我不确定JPA 2.1。谢谢你的帮助。