【发布时间】:2015-07-16 22:47:06
【问题描述】:
我有基于 spring boot 1.2.3 的应用程序。其中一个模型非常具体:包含枚举列表。当我尝试通过 spring jpa 查询调用时,sql 的一部分消失 [c.categories IN (:category) 替换为 (. in (?))]。我想这可能是图书馆的一些问题,或者我做错了什么。
你知道如何解决这个问题吗?
日志捕获 SQL:
select count(myobject0_.id) as col_0_0_ from myobject myobject0_ cross join myobject0_categories categories1_ where myobject0_.id=categories1_.myobject_id and (. in (?))
错误:
o.h.engine.jdbc.spi.SqlExceptionHelper : SQL Error: 0, SQLState: 07001
java.sql.SQLException: No value specified for parameter 1
来自接口的原始 JPQL:
@Query("from Myobject c where and c.categories IN (:category)")
Page<Myobject> findAll(@Param("category") Set<Category> categories, Pageable pageable);
目标模型包含:
@Column(name = "category")
@Enumerated(EnumType.STRING)
@ElementCollection(fetch = FetchType.LAZY)
@CollectionTable(name = "myobject_categories", joinColumns = @JoinColumn(name = "myobject_id"))
private Set<Category> categories;
枚举模型:
public enum Category {
CATEGORY(1), CATEGORY2(2);
private final Integer id;
Category(Integer id) { this.id=id; }
public Integer getId() { return id; }
}
【问题讨论】:
标签: hibernate spring-boot jpa spring-data-jpa jpql