gpt4 book ai didi

java - 无法通过反射 hibernate 获取字段值

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:17:52 24 4
gpt4 key购买 nike

我在jpa中更新对象时遇到问题

我有bean用户

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

关于这个问题的任何帮助
谢谢

最佳答案

尝试更改映射注释。从 ratingList 中删除 @JoinColumn 注释并添加 mappedBy 属性:

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

其中 userRating 实体中的属性名称,它与 User 具有 @ManyToOne 关联。

关于java - 无法通过反射 hibernate 获取字段值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19763559/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com