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.
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")
.
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 PartFeatureVersion
class. You are restricting the criteria based on PartFeatureVersion.part_id
property. The problem is your PartFeatureVersion
class doesn't have a property called part_id
.