1

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

6
  • I'm not terribly familiar with Hibernate, but is it able to perform this mapping without setters for the mapped fields? Commented Dec 28, 2013 at 7:29
  • I am also not sure but it looks there is part_id should be in CAPS for @JoinColumn(name="part_id") Commented Dec 28, 2013 at 7:43
  • Make sure the name of columns match exactly as they are named in db. Commented Dec 28, 2013 at 7:58
  • I have tried part_id as caps in @JoinColumn(name="PART_ID", itdidn't work well.As well all db names are match with pojo classes. Commented Dec 28, 2013 at 8:10
  • Here getters and setters are not created in the pojo class, if i creating pojo then its error "org.hibernate.MappingException: Repeated column in mapping for entity:" Commented Dec 28, 2013 at 8:14

2 Answers 2

7

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.

Sign up to request clarification or add additional context in comments.

2 Comments

I have changed the code , but now i'm getting error as org.hibernate.PropertyAccessException: IllegalArgumentException occurred calling getter of Part.part_id.
Do you forget to replace part.getPart_id() into part?
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.