Guy*_*ood 5 hibernate spring-data-jpa
我正在使用 hibernate YesNoConverter 在数据库中将布尔值存储为“Y”/“N”。目前,我正在迁移到 Spring Boot 3.0(使用 spring-data-jpa:3.0.0),并且自定义 JpaRepository 查询“findByActiveFalse”崩溃。
List<ExampleEntity> findByActiveFalse();
Run Code Online (Sandbox Code Playgroud)
错误:
org.springframework.dao.DataIntegrityViolationException: JDBC exception executing SQL [select e1_0.id,e1_0.active from example_entity e1_0 where e1_0.active=0]; SQL [n/a]
Run Code Online (Sandbox Code Playgroud)
Hibernate YesNoConverter 不会被触发,因此有一个零而不是“N”。(在升级到 Spring Boot 3.0 之前,我有一个自己的 Converter 实现,它也有同样的问题)
使用“findByActive(false)”,查询可以正常工作。
这是我的资料来源:
我需要配置什么才能让它像以前一样工作吗?
由于您不想重构代码,因此这是一个很好的临时解决方案。
public interface ExampleRepository extends JpaRepository<ExampleEntity, String> {
List<ExampleEntity> findByActive(boolean active);
default List<ExampleEntity> findByActiveFalse(){
return findByActive(false);
}
}
Run Code Online (Sandbox Code Playgroud)
选择:
@Query("select e FROM exampleentity where e.active= true");
Run Code Online (Sandbox Code Playgroud)
使用标准构建器:
builder.equals(root.get("repeat), true);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
499 次 |
| 最近记录: |