java - 是否可以将 PostgreSQL 中的字符字段转换为 JPA 命名查询中的整数?

标签 java hibernate postgresql jpa seam

@Table(name = "Table")
class Table{
 String a
 Integer b
}

此处表 t 中的列 a 是字符 varying(32)

这两种方法我都试过了,但都出错了。

SELECT t.b from Table t where Integer.parseInt(t.a) > 0 
Error : Caused by: org.postgresql.util.PSQLException: ERROR: schema "integer" does not exist

SELECT t.b from Table t where (t.a::integer) > 0 
Error : invalid token :: at line <line number>

谢谢

最佳答案

以下查询对我来说效果很好。

SELECT t.b FROM table t WHERE CAST(t.a AS integer) > 0 

关于java - 是否可以将 PostgreSQL 中的字符字段转换为 JPA 命名查询中的整数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9090830/

相关文章:

java - Apache Camel 有条件的 onCompletion() 用于特定的 SEDA 消费者 .choice()

java - Websocket 无法建立连接

java - JFreeChart 饼图未在 RCP View 部分中展开

java - Maven tomcat :run issue

java - Hibernate session.get() 显示空

java - IndexColumn 注释中的基本属性

java - Hibernate query.list() 需要很长时间才能响应

postgresql - 使用数组参数调用存储过程的 ECPG

ruby-on-rails - rails 3/postgres - 如果不应用 :limit in schema 字符串有多长

mysql - 从 postgresql 迁移到 Mysql