java - org.hibernate.type.NumericBooleanType 不转换 JPASQLQuery 中的值
问题描述
在我的模型中,我声明了这个 NumericBooleanType 属性:
@Column(name = "ST_ATIVO", nullable = false)
@Type(type = "org.hibernate.type.NumericBooleanType")
private Boolean ativo;
然后,在另一个类中,我正在尝试执行以下查询:
List<Long> test = this.sqlQueryFactory.query()
.select(equipe.id)
.from(equipe)
.where(equipe.ativo.isTrue())
.fetch();
但是,我收到了这个错误:
org.hibernate.exception.SQLGrammarException: could not extract ResultSet
Caused by: org.postgresql.util.PSQLException: ERROR: operator does not exist: integer = boolean
查询中的 NumericBooleanType 布尔属性不应该被休眠转换为 int 吗?
解决方案
目前尚不清楚您使用什么查询 api。假设您使用querydsl,您可以尝试以这种方式更正您的查询:
JPAQueryFactory queryFactory = new JPAQueryFactory(entityManager);
List<Long> test = queryFactory.query()
.select(equipe.id)
.from(equipe)
.where(equipe.ativo.eq(true))
.fetch();
推荐阅读
- html - 引导模式
- c++ - 如何在 iOS 上调用使用 OpenCV C++ 的 Flutter 插件?
- authentication - Nuxt Auth Module 使用 serverMiddleware 还是客户端之一?
- neo4j - 如何在 Neo4j 密码查询中包含特定于展开块中返回的每个节点的关系列表?
- reactjs - Reactjs REST API未打印到屏幕
- javascript - 如何在 React js 中使用全局变量?
- javascript - 如果在通过 nodejs 扫描时 mp3 文件损坏,如何处理错误
- c - 检查子进程是否已在 Unix 上的 C 中终止而没有阻塞
- javascript - 坏:如何将动画添加到我的照片中
- opencv - 如何检测视频中的散帧