简体   繁体   中英

How to enable the MySQL BINARY operator in Hibernate queries and Session.get()

Is it possible to fetch the record using HQL against MySQL with a query like this?

 select * from students where binary sid='s001' 

I am using hibernate 4.3 and this BINARY operator is not recognized by Hibernate. If I want to achieve the same with Session.get() , what do I have to do?

Both MySQL and HQL support the CAST() function so you can rewrite your query as:

select * 
from students 
where CAST(sid as binary) = CAST('s001' as binary) 

For Session.get() you need to use the @Loader Hibernate custom annotation. You can find more on the @Loader usage here.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM