Hibernate Criteria - org.hibernate.QueryException:无法解析属性:

时间:2013-12-28 07:25:03

标签: java hibernate orm criteria hibernate-mapping

我正在尝试使用条件从多对一关系映射字段中选择值。但是我收到错误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;
}

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

2 个答案:

答案 0 :(得分:7)

更改以下代码:

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

成:

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

代码中的条件基于PartFeatureVersion类。您基于PartFeatureVersion.part_id属性限制条件。问题是您的PartFeatureVersion类没有名为part_id的属性。

答案 1 :(得分:0)

这发生在我身上。

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