mysql - JPQL中的BINARY运算符等价的是什么?

标签 mysql jpa jpql

JPQL中是否有等同于SQL BINARY的运算符?
我在谷歌上搜索了很多,发现没有人提到它。

提前致谢!


对于 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有关...)

最佳答案

我仍然无法在 JPQL 中找到 BINARY 的等效运算符。
但是如果你遇到这个问题,有一个解决方法:
在 JPA 中,只需使用 em.createNativeQuery() 就可以使用 SQL,因此您可以使用 BINARY 运算符。 像这样:

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

只为遇到同样问题的人提供解决方案。

关于mysql - JPQL中的BINARY运算符等价的是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21181192/

相关文章:

php - 来自 PHP 的 MySQL 查询返回不正确的结果

mysql - 从 db2 制作输出文件显示从 shell 脚本创建表的过程?

php - 查询日期数组以仅显示 future 事件 - PHP

java - 使用 JPA 映射双向一对多 Hibernate 实体

json - 在查询中选择特定列时如何将数组结果转换为 JSON 格式

MySQL:有没有办法将值从一个表插入到另一个表?

java - JPA:为什么每个具体类实现表是可选的?

java - 使用@OneToMany时JPA结果无限循环

java - 无法对 JPQL 中的列进行 ORDER BY

jpa - QueryDSL 按顺序合并