通过反射休眠不能获得字段值 [英] could not get a field value by reflection hibernate
问题描述
在jpa中更新对象时遇到问题
我有bean用户
public class User $
$ b @Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name =id,unique = true,nullable =假)
私人长ID;
@Column(name =name,nullable = false)
私有字符串名称;
@OneToMany(fetch = FetchType.EAGER)
@JoinColumn(name =fk_program_rating)
private List< Rating> ratingList = new ArrayList< Rating>();
}
和
<$ p
$ b @GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name =id)public class Rating extends BaseModel {
@Id
@GeneratedValue ,unique = true,nullable = false)
私人长ID;
@ManyToOne()
@JoinColumn(name =fk_program_rating,nullable = false)
@ForeignKey(name =FK_prog_rate)
@OnDelete(action = OnDeleteAction.CASCADE )
私人节目节目;
}
当尝试更新时,给我例外:无法获得字段值当表评级有行时发生的反射
$ b
ERROR TransactionInterceptor:434 - 由提交异常覆盖的应用程序异常
blockquote>
com .vodafone.visradio.dataaccess.exception.DataAccessException:org.hibernate.PropertyAccessException:无法通过反射获取字段值getter of com.vodafone.visradio.dataaccess.model.Rating.id
有关此问题的任何帮助
thanks解决方案尝试更改映射注释。从
ratingList
中移除@JoinColumn
注释,并添加mappedBy
属性:
@OneToMany(fetch = FetchType.EAGER,mappedBy =user)
private List< Rating> ratingList = new ArrayList< Rating>();
其中
user
是评级
与用户
具有@ManyToOne
关联的实体。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 fromratingList
and addmappedBy
attribute:@OneToMany(fetch = FetchType.EAGER, mappedBy = "user") private List<Rating> ratingList = new ArrayList<Rating>();
where
user
is the property name in theRating
entity that has a@ManyToOne
association withUser
.这篇关于通过反射休眠不能获得字段值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!