当前位置: 首页 > 知识库问答 >
问题:

无法找到此ManagedType上具有给定名称[XXX]的属性[未知]

万坚壁
2023-03-14

我有这个实体,它的ID定义在可识别类。

InventoryLoad的主键为InventoryLoadID

public class InventoryLoad extends AbstractIdentifiable<InventoryLoadId> implements Auditable {

    @OneToMany(mappedBy = "inventoryLoad")
    private Set<InventorySubLoad> inventorySubLoads = Sets.newLinkedHashSet();

    @ManyToOne(fetch = FetchType.LAZY, optional = false)
    @JoinColumns({
            @JoinColumn(name = "stoloc", referencedColumnName = "stoloc"),
            @JoinColumn(name = "wh_id", referencedColumnName = "wh_id")
    })
    private Location location;

    @Column(name = "lodwgt")
    private Double loadWeight;

    @Column(name = "prmflg")
    private Boolean permanentLoadSubFlag;
}

这是上述类的ID

@Embeddable
public class InventoryLoadId extends AbstractIdentifiableId {
    private static final long serialVersionUID = 1L;


    @Column(name = "lodnum")
    private String loadNumber;

    // some another code below
}

我正在使用Criteria builder访问ID类的列。

要使用 Path 来获取此信息以获取 PK 的库存 ID 的路径。

Session session = new HibernateTools().getSession();

CriteriaBuilder criteriaBuilder = session.getCriteriaBuilder();
CriteriaQuery<Object[]> criteriaQuery = criteriaBuilder.createQuery(Object[].class);

Root<InventoryLoad> inventoryLoadRoot = criteriaQuery.from(InventoryLoad.class);
Path<InventoryLoadId> inventoryLoadIdPath = inventoryLoadRoot.get("id");
criteriaQuery.multiselect(inventoryLoadIdPath.get("loadNumber"),

获取此错误

无法定位属性


共有1个答案

安毅
2023-03-14

hibernate中的条件可以与JPA静态元模型配合使用。试着使用它

@Embeddable
public class InventoryLoadId extends AbstractIdentifiableId {
    private static final long serialVersionUID = 1L;

    @Column(name = "lodnum")
    private String loadNumber;

}

@Generated(value = "org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor")
@StaticMetamodel(InventoryLoadId.class)
public abstract class InventoryLoadId_ {

    public static volatile SingularAttribute<InventoryLoadId, String> loadNumber;

}

Session session = new HibernateTools().getSession();
CriteriaBuilder criteriaBuilder = session.getCriteriaBuilder();

// create the query
CriteriaQuery<InventoryLoadId> query = criteriaBuilder.createQuery(InventoryLoadId.class);

// set the root class
Root<InventoryLoadId> inventoryLoadRoot = query.from(InventoryLoadId.class);

query.multiselect(inventoryLoadRoot.get(InventoryLoadId_.loadNumber).alias("loadNumber"));
 类似资料: