2013-11-04 60 views
4

我有問題,當在JPA更新對象無法得到通過反射的字段值冬眠

我有豆用戶

public class User { 

    @Id 
    @GeneratedValue(strategy = GenerationType.IDENTITY) 
    @Column(name = "id", unique = true, nullable = false) 
    private Long id; 
    @Column(name = "name", nullable = false) 
    private String name; 
    @OneToMany(fetch = FetchType.EAGER) 
    @JoinColumn(name = "fk_program_rating") 
    private List<Rating> ratingList = new ArrayList<Rating>(); 
} 

public class Rating extends BaseModel { 

    @Id 
    @GeneratedValue(strategy = GenerationType.IDENTITY) 
    @Column(name = "id", unique = true, nullable = false) 
    private Long id; 
    @ManyToOne() 
    @JoinColumn(name = "fk_program_rating", nullable = false) 
    @ForeignKey(name = "FK_prog_rate") 
    @OnDelete(action = OnDeleteAction.CASCADE) 
    private Program program; 
} 

時,試圖更新給我例外情況:無法通過反映 得到的字段值發生在表格評級有行時

ERROR TransactionInterceptor:434 - 應用程序異常被提交異常覆蓋 com.vodafone.visradio.dataaccess.exception.DataAccessException:org.hibernate.PropertyAccessException:無法通過com.vodafone.visradio的反射getter獲取字段值。 dataaccess.model.Rating.id

有關此問題的任何幫助
感謝

+0

您是如何嘗試通過反射訪問它的? – m3th0dman

+0

@ m3th0dman:我沒有通過反射訪問任何東西 – abdelhady

+1

那麼你的評級類有一個getter方法你的'ID'屬性? – Matthias

回答

5

嘗試改變映射的註釋。從ratingList取出@JoinColumn標註和添加mappedBy屬性:

@OneToMany(fetch = FetchType.EAGER, mappedBy = "user") 
private List<Rating> ratingList = new ArrayList<Rating>(); 

其中user是在具有與User一個@ManyToOne協會Rating實體屬性名稱。