我有一个实体,比如说 A,它有一个字段是另一个实体的列表,比如说 B。
这是一个:
@Entity
@Table(name = "a")
public class A implements Serializable{
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "sequenceGenerator")
@SequenceGenerator(name = "sequenceGenerator")
private Long id;
@ManyToMany
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
@JoinTable(name = "a_b",
joinColumns = @JoinColumn(name="as_id", referencedColumnName="id"),
inverseJoinColumns = @JoinColumn(name="bs_id", referencedColumnName="id"))
private Set<B> bs = new HashSet<>();
}
这是乙:
@Entity
@Table(name = "b")
public class B implements Serializable{
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "sequenceGenerator")
@SequenceGenerator(name = "sequenceGenerator")
private Long id;
@NotNull
@Column(name = "name", nullable = false)
private String name;
@Column(name = "description")
private String description;
}
现在,我想要实现的是能够查询 A 的所有条目 a,在 a.bs 中有一个 B 的实体 b
实际查询如下所示:
@Repository
public interface ARepository extends JpaRepository<A, Long> {
@Query("SELECT DISTINCT a FROM A a LEFT JOIN FETCH a.bs bs WHERE :b MEMBER OF bs")
List<A> findAllByB(@Param("b") B b);
}
它不应该像这样工作吗?
但是我得到的错误是下面的错误,由于超出了帖子的大小限制,我把它放在了 pastebin 上: