Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

could not get a field value by reflection hibernate

I have problem when update object in jpa

i have bean user

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>();
}

and

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

when try to update that give me exception : could not get a field value by reflection that happen when table rating have rows

ERROR TransactionInterceptor:434 - Application exception overridden by commit exception com.vodafone.visradio.dataaccess.exception.DataAccessException: org.hibernate.PropertyAccessException: could not get a field value by reflection getter of com.vodafone.visradio.dataaccess.model.Rating.id

any help about this problem
thanks

like image 257
abdelhady Avatar asked Nov 04 '13 07:11

abdelhady


1 Answers

Try changing the mapping annotations. Remove the @JoinColumn annotation from ratingList and add mappedBy attribute:

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

where user is the property name in the Rating entity that has a @ManyToOne association with User.

like image 196
Debojit Saikia Avatar answered Oct 13 '22 18:10

Debojit Saikia