[英]JPA-Hibernate - “could not get a field value by reflection getter of with inheritance
[英]could not get a field value by reflection hibernate
我在 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;
}
当尝试更新时给我异常:无法通过反射获得字段值,当表评级有行时发生
错误 TransactionInterceptor:434 - 应用程序异常被提交异常 com.vodafone.visradio.dataaccess.exception.DataAccessException: org.hibernate.PropertyAccessException: 无法通过 com.vodafone.visradio.dataaccess.model.Rating 的反射获取器获取字段值。ID
关于这个问题的任何帮助
谢谢
尝试更改映射注释。 取出@JoinColumn
从注释ratingList
和添加mappedBy
属性:
@OneToMany(fetch = FetchType.EAGER, mappedBy = "user")
private List<Rating> ratingList = new ArrayList<Rating>();
其中user
是Rating
实体中与User
具有@ManyToOne
关联的属性名称。
可能导致这种情况的另一件事是,如果您没有完全正确地执行您的标准。
例如,如果您将"rating"
放在标准中,但您实际上需要"rating.id"
。 这将导致出现相同的错误消息。
因此,如果您检查了实体定义,请检查以确保在失败的实际查询中没有像这样的简单错误。 这就是我遇到类似错误时的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.