问题:ManyToMany实体的规范查询语法

时间:2019-06-06 12:43:50

标签: java spring jpa many-to-many specifications

我想找到类A的所有对象(类A与类B具有多对多关系),这些对象中至少有一个B类对象集中的一个对象,并且在字段中具有某个值。

虽然我可以四处走动,但仍在互联网上搜索文档,尽管创建了摘要描述的发票清单,但我很好奇我是否能够使用纯规范进行书写。

@ManyToMany(mappedBy = "A.name")
 public class A {
   private Set<B> b; 
 }

@JoinTable(name = "AB",
joinColumns = {@JoinColumn(name = "B_id", referencedColumnName = "id")},                 
inverseJoinColumns ={@JoinColumn(name= "A_id",referencedColumnName="id")})
@ManyToMany(cascade = {CascadeType.PERSIST, CascadeType.MERGE})
 public class B
 {
     private Object certainField;
     private Set<A> a;
 }

 public static Specification<A> hasB(Set<B> b) {
     return (a, cq, cb) -> {

         //I want to find all the Objects<A> which have an Element B with 
        // CertainField.equals(aValue);
       //     I find it hard to understand the syntax and i find no clue how 
     // to 
    //     make it work. 

    };
}

0 个答案:

没有答案