use*_*031 1 java orm hibernate 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;
}
Run Code Online (Sandbox Code Playgroud)
如果在PartFeatureVersion pojo类中创建getter/setter,则给出错误为org.hibernate.MappingException: Repeated column in mapping for entity:PART_ID (should be mapped with insert="false" update="false").
更改以下代码:
partCriteria.add(Restrictions.eq("part_id",part.getPart_id()));
Run Code Online (Sandbox Code Playgroud)
成:
partCriteria.add(Restrictions.eq("part", part));
Run Code Online (Sandbox Code Playgroud)
代码中的条件基于PartFeatureVersion类.您正在根据PartFeatureVersion.part_id属性限制条件.问题是你的PartFeatureVersion类没有一个叫做的属性part_id.
| 归档时间: |
|
| 查看次数: |
28827 次 |
| 最近记录: |