Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jpa 映射联接的where子句中的条件api集合谓词_Jpa_Jpa 2.0_Criteria_Criteria Api - Fatal编程技术网

Jpa 映射联接的where子句中的条件api集合谓词

Jpa 映射联接的where子句中的条件api集合谓词,jpa,jpa-2.0,criteria,criteria-api,Jpa,Jpa 2.0,Criteria,Criteria Api,我在设置以下查询的where子句时遇到一些问题: CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<Configuration> cq = cb.createQuery(Configuration.class); Root<Configuration> conf = cq.from(Configuration.class); MapJoin<Configuration, String,

我在设置以下查询的
where
子句时遇到一些问题:

CriteriaBuilder cb = em.getCriteriaBuilder();
  CriteriaQuery<Configuration> cq = cb.createQuery(Configuration.class);
  Root<Configuration> conf = cq.from(Configuration.class);
  MapJoin<Configuration, String, Component> mapJoin = conf.join(Configuration_.components, JoinType.LEFT); 
  cq.where(cb.and(cb.like(mapJoin.key(), "%abc%"), 
             cb.like(mapJoin.value().get(Component_.displayName), "%def%")));
  cq.select(pc);

提前感谢您,感谢您的帮助。

您遇到了什么错误

你的代码没有意义。在JPA中,默认情况下,映射键被假定来自目标对象,如果您没有使用@MapKey设置用于键的目标字段,那么默认情况下,它被假定为对象的Id。在这种情况下,您的键是字符串,Id是长的,所以我看不出这有什么作用

您需要提供一个@MayKey或@MapKeyColumn来在联接表中独立地存储该键

@Entity
public class Configuration{
  @Id
  protected Long id;       
  @OneToMany
   protected Map<String, Component> components;
}
@Entity
public class Component{
    @Id
    protected Long id;    
    protected String displayName;
}