[英]could not get a field value by reflection hibernate
I have problem when update object in jpa我在 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
错误 TransactionInterceptor:434 - 应用程序异常被提交异常 com.vodafone.visradio.dataaccess.exception.DataAccessException: org.hibernate.PropertyAccessException: 无法通过 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:取出
@JoinColumn
从注释ratingList
和添加mappedBy
属性:
@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
.其中
user
是Rating
实体中与User
具有@ManyToOne
关联的属性名称。
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"
.例如,如果您将
"rating"
放在标准中,但您实际上需要"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.
这就是我遇到类似错误时的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.