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
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
.
Another thing that can cause this is if you don't quite do your criteria correctly.
For example if you put "rating"
in the criteria, but you actually need "rating.id"
. That will cause this same error message to come up.
So if you've checked your Entity definitions check to make sure you don't have a simply mistake like this in the actual query that is failing. That was the issue when I was getting a similar error.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.