gpt4 book ai didi

java - Spring data CrudRepository findBy 关系

转载 作者:行者123 更新时间:2023-12-01 20:18:00 25 4
gpt4 key购买 nike

我想选择所有具有状态为新的 Bar 的 Foo 实体。

这是我尝试过的:

@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'

最佳答案

SELECT f FROM Foo AS f JOIN f.bars AS b WHERE b.status = 'NEW'

关于java - Spring data CrudRepository findBy 关系,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45425834/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com