【发布时间】:2018-01-07 14:42:41
【问题描述】:
我想选择所有 Foo 实体,它们的任何 Bars 都具有新状态。
这是我尝试过的:
@Entity
@Table(name = "FOO")
class Foo {
@Id
@Column(name = "ID")
@GeneratedValue(strategy= GenerationType.IDENTITY)
private Long id;
@OneToMany
private Set<Bar> bars;
//...
}
public interface FooRepository extends CrudRepository<Foo, Long> {
@Query("select m from Foo f where f.bars.status = 'NEW' ")
public Page<Foo> findByBarStatus(Pageable pageable);
}
但我明白了:
org.hibernate.exception.SQLGrammarException: could not prepare statement
我也尝试过编写 join 语句:
select f from Foo f inner join f.bars b where b.status = 'NEW'
【问题讨论】:
标签: java sql spring spring-data spring-data-jpa