I have tried to cast to float numbers from string in the database fields to compare with another numbers. The field in the database was String type. I have tried to use BETWEEN criteria using cast() as " cast(field, float) BETWEEN 1.003 AND 100.00)" in the where statement. however, it does not help.
however, when I tried to execute the regular query directly to Database without Hibernate, it works fine as "SELECT * FROM table WHERE cast(field as float) BETWEEN 1.003 AND 100.00"
I have tried ".. WHERE cast(field as float) > 1.003 AND cast(field as float) < 100", however it does not work on Hibernate either.
I found several blogs or forms, but it does not help.
https://forum.hibernate.org/viewtopic.php?p=2399159
Do you have any idea w开发者_运维技巧hat was wrong or any opinion ?
I will appreciate about that if you give some directions.
Thanks
tiger
- Are you getting an illegal syntax exception from Hibernate or a database error? Can you post it?
- What database are you using? Does it support
cast()
internally? - Have you tried doing your comparison without cast()? Some (most, actually) databases support implicit type conversion
精彩评论