Tôi đang cố gắng để lọc kết quả thiết lập bởi một chìa khóa nước ngoài:Không thể lấy một giá trị trường bằng cách phản ánh getter
createCriteria(Person.class).add(Restrictions.ne("position", 1L)).list()
Nhưng nhận được ngoại lệ này: org.hibernate.PropertyAccessException: could not get a field value by reflection getter of com.example.model.Position.id
Dưới đây là các thực thể JPA cần thiết (tỉa xuống đến các lĩnh vực cần thiết):
@Entity
@Table
public class Person {
@Id
@GeneratedValue
private Long id;
@ManyToOne
@JoinColumn(nullable = false)
@ForeignKey(name = "person_position_fkey")
private Position position;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Position getPosition() {
return position;
}
public void setPosition(Position position) {
this.position = position;
}
}
@Entity
@Table
public class Position {
@Id
@GeneratedValue
private Long id;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
}
Hãy thử 'Restrictio ns.ne ("position.id", 1L) ' –
Cảm ơn bạn! Điều đó đã giải quyết được vấn đề của tôi. Bạn có thể cung cấp nó như là một câu trả lời? Vì vậy, tôi có thể chấp nhận nó. – dtrunk