Java 休眠条件 - org.hibernate.QueryException:无法解析属性:

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20812125/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 04:31:41  来源:igfitidea点击:

Hibernate Criteria - org.hibernate.QueryException: could not resolve property:

javahibernateormcriteriahibernate-mapping

提问by user2848031

I'm trying to use criteria for select the values from many-to-one releationship mapped field.But i'm getting errororg.hibernate.QueryException: could not resolve property:part_id of:. Please see my pojo classes and advise what is the wrong here.

我正在尝试使用标准从多对一关系映射字段中选择值。但我收到错误org.hibernate.QueryException: could not resolve property:part_id of:。请查看我的 pojo 课程并告知这里有什么问题。

Criteria partCriteria = session.createCriteria(PartFeatureVersion.class);
partCriteria.add(Restrictions.eq("part_id",part.getPart_id()));


@Entity
@Table(name="DBO.PART_FEATURE_VERSION")
public class PartFeatureVersion {
private Part part;

@ManyToOne(fetch=FetchType.LAZY)
    @JoinColumn(name="part_id")
    public Part getPart() {
        return part;
    }


@Entity
@Table(name="DBO.PART")
public class Part {

private String part_id;
    private Set<PartFeatureVersion> partfeatureversion = new HashSet<PartFeatureVersion>(0);

    @Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name="PART_ID")
public String getPart_id() {
    return part_id;
}

    @OneToMany(cascade=CascadeType.ALL,fetch=FetchType.LAZY,mappedBy="part")
public Set<PartFeatureVersion> getPartfeatureversion() {
    return partfeatureversion;
}

if create getters/setters in PartFeatureVersion pojo class , its giving error as org.hibernate.MappingException: Repeated column in mapping for entity:PART_ID (should be mapped with insert="false" update="false").

如果在 PartFeatureVersion pojo 类中创建 getter/setter,则其给出的错误为org.hibernate.MappingException: Repeated column in mapping for entity:PART_ID (should be mapped with insert="false" update="false").

采纳答案by jocki

Change the following code:

更改以下代码:

partCriteria.add(Restrictions.eq("part_id",part.getPart_id()));

into:

进入:

partCriteria.add(Restrictions.eq("part", part));

The criteria in your code is based on PartFeatureVersionclass. You are restricting the criteria based on PartFeatureVersion.part_idproperty. The problem is your PartFeatureVersionclass doesn't have a property called part_id.

代码中的标准基于PartFeatureVersion类。您正在限制基于PartFeatureVersion.part_id财产的标准。问题是您的PartFeatureVersion班级没有名为part_id.

回答by javaprogrammingmx

This happened to me.

这发生在我身上。

I fixed it by matching the sintax's upper and lower case description field when used in the criteria, and match the fielname declared in the DTO class.

我通过在标准中使用时匹配 sintax 的大写和小写描述字段来修复它,并匹配 DTO 类中声明的 fielname。