1

我需要验证 binUse 的属性首字母缩写词是否等于BinUseAcronym.FPAN.toString()。我需要访问 binUse.acronym

产品箱

@Id
@Column(name = "ID")
private Long id;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "BIN_USE_ID", nullable = false)
private BinUse binUse;

便用

@Id
@Column
private Long id;
@Column
private String acronym;

我的条件查询

ProductBin productBin = this.productBinRepository.findOne(new Specification<ProductBin>() {
    @Override
    public Predicate toPredicate(Root<ProductBin> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
        List<Predicate> listPredicate = new ArrayList<>();
        listPredicate.add(cb.equal(root.get("start"), bin.getStart()));
        listPredicate.add(cb.equal(root.get("end"), bin.getEnd()));
        listPredicate.add(cb.equal(
            root.get("BinUse_.acronym"), BinUseAcronym.FPAN.toString())
        );

        return cb.and(listPredicate.toArray(new Predicate[listPredicate.size()]));
    }
});

我尝试在属性之前添加类名,但我不断收到异常:

InvalidDataAccessApiUsageException: Unable to locate Attribute  with the the given name [BinUse_.acronym] on this ManagedType [com.edenred.commons.domain.ProductBin]; 

如何解决此错误?

4

0 回答 0