开发者

Cast function for Hibernate

开发者 https://www.devze.com 2022-12-10 01:55 出处:网络
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() a

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


  1. Are you getting an illegal syntax exception from Hibernate or a database error? Can you post it?
  2. What database are you using? Does it support cast() internally?
  3. Have you tried doing your comparison without cast()? Some (most, actually) databases support implicit type conversion
0

精彩评论

暂无评论...
验证码 换一张
取 消