次のクラス仕様を組み立てました。
public ItemVendedorSpecification(String descricao, List<Long> categorias, List<Long> fabricantes, List<Long> vendedores) {
super();
this.descricao = descricao;
this.categorias = categorias;
this.fabricantes = fabricantes;
this.vendedores = vendedores;
}
@Override
public Predicate toPredicate(Root<ItemVendedor> root, CriteriaQuery<?> query, CriteriaBuilder builder) {
if (!descricao.isEmpty()) {
String PalavraChave[] = descricao.split(" ");
for (String filtro : PalavraChave) {
predicates.add(builder.like(builder.upper(root.get("id").get("produto").get("descricaoDetalhada")), "%" + filtro.toUpperCase() + "%"));
}
}
predicates.add(builder.isTrue(root.get("disponivel")));
if(!fabricantes.isEmpty()) {
predicates.add(root.get("id").get("produto").get("fabricante").get("id").in(fabricantes));
}
if(!vendedores.isEmpty()) {
predicates.add(root.get("id").get("vendedor").get("id").in(vendedores));
}
if(!categorias.isEmpty()) {
predicates.add(root.join("id").get("produto").get("categorias").get("id").in(categorias));
}
return builder.and(predicates.toArray(new Predicate[1]));
}
}
カテゴリ基準を挿入するものを除いて、ほぼすべての述語が機能しています。うまくいかず、作成に苦労しています。
次のエラーを返す方法で:
"Illegal attempt to dereference path source [null.produto.categorias] of basic type; nested exception is java.lang.IllegalStateException: Illegal attempt to dereference path source [null.produto.categorias] of basic type"
もしこれを作るのを手伝ってくれる人はいますか?
以下は、ItemSeller クラスの詳細です。
public class ItemVendedor implements Serializable{
private static final long serialVersionUID = 1L;
private ItemVendedorPK id = new ItemVendedorPK();
private BigDecimal preco;
private Boolean disponivel;
private Date dt_insert;
private Date dt_update;
private BigDecimal desconto;
public ItemVendedor() {
}
public ItemVendedor(Produto produto, Vendedor vendedor, BigDecimal preco, BigDecimal desconto ,Boolean disponivel) {
super();
this.id.setProduto(produto);
this.id.setVendedor(vendedor);
this.preco = preco;
this.disponivel = disponivel;
this.desconto = desconto;
}
//GETs and SETs
ご覧のとおり、 と で構成されるキーである id というフィールドがVendedor vendedor
ありProduto produto
ます。
Produto クラス内には List Categorias があります。製品の場合、複数のカテゴリに属することができます。
次に、クラス カテゴリには、id.
私が仕様に入れたいのは、別のリスト List Categorias でパラメーターとして引用したカテゴリーのリスト内にあるすべての ItemVendedor を取得する方法です。