【问题标题】:Could not get a field value by reflection getter无法通过反射 getter 获取字段值
【发布时间】:2013-08-15 03:27:49
【问题描述】:

我正在尝试通过外键过滤结果集:

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)
  • 谢谢!这解决了我的问题。你能提供它作为答案吗?所以我可以接受。

标签: java hibernate hibernate-criteria


【解决方案1】:

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

【讨论】:

  • 加上解释就更好了
猜你喜欢
  • 1970-01-01
  • 2015-12-08
  • 2014-12-03
  • 2019-04-22
  • 2016-12-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多