我想选择任何具有新状态栏的Foo实体。春季数据CrudRepository findBy关系
这里是我的尝试:
@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
我也试着写连接语句代替:
select f from Foo f inner join f.bars b where b.status = 'NEW'
您忘记'AS's – Snickers3192
'因为'不是强制性的。 –
@AbdullahKhan你只是吹我的脑海里。 – Snickers3192