14

I'm trying to filter a result set by a foreign key:

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

But getting this exception: org.hibernate.PropertyAccessException: could not get a field value by reflection getter of com.example.model.Position.id

Here are the necessary JPA entities (trimmed down to the necessary fields):

@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;
    }
}
DataNucleus
  • 15,497
  • 3
  • 32
  • 37
dtrunk
  • 4,685
  • 17
  • 65
  • 109

1 Answers1

26

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

Yurii Shylov
  • 1,219
  • 1
  • 10
  • 19