簡體   English   中英

無法通過反射getter獲取字段值

[英]Could not get a field value by reflection getter

我正在嘗試通過外鍵過濾結果集:

createCriteria(Person.class).add(Restrictions.ne("position", 1L)).list()

但是得到這個異常: org.hibernate.PropertyAccessException: could not get a field value by reflection getter of com.example.model.Position.id

以下是必要的JPA實體(修剪到必要的字段):

@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;
    }
}

試試Restrictions.ne("position.id", 1L)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM