无法在此托管类型[未知]上使用给定名称[XXX]找到属性



我具有该实体,其ID在可识别类中定义。

库存载荷具有库存loadID作为其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
}

我正在使用标准构建器进入ID类的列。

使用该路径获取invatchoryId的路径,即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"),

获取此错误

Unable to locate Attribute  with the the given name [loadNumber] on this ManagedType [unknown]

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

相关内容

  • 没有找到相关文章

最新更新