简体   繁体   English

无法通过反射休眠获取字段值

[英]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 .其中userRating实体中与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.

相关问题 JPA-Hibernate-“无法通过继承的反射获取器获取字段值 - JPA-Hibernate - “could not get a field value by reflection getter of with inheritance PropertyAccessException:使用Hibernate时无法通过反射getter获取字段值 - PropertyAccessException: could not get a field value by reflection getter While using Hibernate org.hibernate.PropertyAccessException:无法通过反射getter获取字段值 - org.hibernate.PropertyAccessException: could not get a field value by reflection getter of 休眠-此映射正确吗? 无法通过反射吸气剂获得字段值? - Hibernate - Is this mapping correct? could not get a field value by reflection getter? 错误:-org.hibernate.PropertyAccessException:无法通过反射获取器获取字段值 - Error :- org.hibernate.PropertyAccessException: could not get a field value by reflection getter 简单的Hibernate应用程序无法正常工作:PropertyAccessException:无法通过反射getter获取字段值 - Simple Hibernate Application not working: PropertyAccessException: could not get a field value by reflection getter of 无法通过反射getter和查询来求和一个字段,以求纯Hibernate中的多列求和 - could not get a field value by reflection getter and query to sum multiple columns in pure Hibernate PropertyAccessException:无法通过反射获取器获取字段值 - PropertyAccessException: could not get a field value by reflection getter 无法通过反射getter获取字段值 - Could not get a field value by reflection getter Hibernate / JPA:无法通过反射设置器设置字段值 - Hibernate/JPA: could not set a field value by reflection setter
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM