参数值[1]与预期的类型[java.lang.Boolean]不匹配 [英] Parameter value [1] did not match expected type [java.lang.Boolean]
问题描述
我在线程"main" org.springframework.dao.InvalidDataAccessApiUsageException中得到错误 Exception:参数值[1]与预期的类型[java.lang.Boolean]不匹配;嵌套的异常是java.lang.IllegalArgumentException:参数值[1]与预期的类型[java.lang.Boolean]
不匹配.
I'm getting the error Exception in thread "main" org.springframework.dao.InvalidDataAccessApiUsageException: Parameter value [1] did not match expected type [java.lang.Boolean]; nested exception is java.lang.IllegalArgumentException: Parameter value [1] did not match expected type [java.lang.Boolean]
.
我对此感到困惑,因为它来自以下所示的服务方法,已被注释掉.当我注释掉时,避免了该错误. active
列是 TINYINT(1)
,它是 1
或 0
.
I'm confused by this because it's coming from the service method shown below that is commented out. When I comment it out, the error is avoided. The active
column is a TINYINT(1)
that's either 1
or 0
.
实体:
@Entity
@NamedQueries({
@NamedQuery(name="Workflow.findByUUID", query="SELECT w FROM Workflow w WHERE w.uuid = :uuid"),
@NamedQuery(name="Workflow.findByActive", query="SELECT w FROM Workflow w WHERE w.active = :active ORDER BY id ASC")
})
我的存储库:
@Repository
public interface WorkflowRepository extends JpaRepository<Workflow, Integer> {
List<Workflow> findByActive(@Param("active") Integer active);
}
我的服务:
@Service
public class WorkflowService {
@Autowired
WorkflowRepository workflowRepository;
/**
* Get active workflows
*/
@Transactional(readOnly = true)
public List<Workflow> findActive() {
//return workflowRepository.findByActive(1);
return null;
}
当我取消评论
推荐答案
您似乎已将 Workflow.active
属性映射为 Boolean
.所以您的存储库应该像:
You seem to have mapped Workflow.active
attribute as a Boolean
. So you repository should be like:
@Repository
public interface WorkflowRepository extends JpaRepository<Workflow, Boolean> {
List<Workflow> findByActive(@Param("active") Boolean active);
}
并且调用 workflowRepository.findByActive(true)
的行为应符合您的期望.
And the call workflowRepository.findByActive(true)
should behave how you want it to.
事实是HQL有时会在数据库映射和Java映射之间产生类型差异,因为在这些环境中键入是不同的.因此,请检查您的 Entity
的 active
类型,以创建适当的 Repository
.
The fact is that HQL sometimes make a type difference between database and Java mapping, because typing isn't the same in these environments. So check your Entity
's active
type to make the appropriate Repository
.
这篇关于参数值[1]与预期的类型[java.lang.Boolean]不匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!