gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 05:25:21 25 4
gpt4 key购买 nike

我有这个实体,其 ID 在 Identifying 类中定义。

InventoryLoad 将 InventoryLoadID 作为其 PK

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 构建器来获取 ID 类列。

要获取此信息,请使用 Path 获取 inventoryid 的路径,即 PK。

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"),

收到此错误

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

最佳答案

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"));

关于java - 无法在此 ManagedType 上找到具有给定名称 [XXX] 的属性 [未知],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56236464/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com