2013-08-13 11 views
14

Próbuję filtrować wynik ustawiona za pomocą klucza obcego:nie udało się uzyskać wartość pola przez odbicie getter

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

ale coraz to wyjątek: org.hibernate.PropertyAccessException: could not get a field value by reflection getter of com.example.model.Position.id

Oto niezbędne podmioty WZP (okrojone do niezbędnych pól):

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

Spróbuj 'ogranicz ns.ne ("position.id", 1L) ' –

+0

Dziękuję! To rozwiązało mój problem. Czy możesz podać to jako odpowiedź? Więc mogę to zaakceptować. – dtrunk

Odpowiedz

24

Spróbuj Restrictions.ne("position.id", 1L)

+0

Dublowałbym to, gdybym mógł. – kapad

Powiązane problemy