gpt4 book ai didi

java - 由 : org. hibernate.PropertyNotFoundException 引起:无法在类上找到字段名称

转载 作者:行者123 更新时间:2023-12-01 18:35:41 24 4
gpt4 key购买 nike

您好,我有 2 个实体国家/地区,具有嵌入的 Id 属性

@IdClass(Country.class)
@Entity
@Table(name="country")
public class Country implements Serializable{
@Id
@Column(name="code", length=3, nullable=false)
private String code;

@Column(name="name", length=256, nullable=false)
private String name;
@EmbeddedId
private CountryLanguage language;

public CountryLanguage getCountryLanguage() {
return language;
}

public void setCountryLanguage(CountryLanguage language) {
this.language = language;
}

具有 getter 和 setter 的 CountryLanguage 嵌入式类

@Embeddable
public class CountryLanguage {

@Column(name="country_code", length=3, nullable=false)
private String code;

@Column(name="language", length=256, nullable=false)
private String language;

@Column(name="is_official", length=256, nullable=false)
private boolean official;

我有一个异常(exception)

Caused by: java.lang.reflect.InvocationTargetException: null springbootapp    
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.8.0_212] springbootapp
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:1.8.0_212] springbootapp
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.8.0_212] springbootapp
at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[na:1.8.0_212] springbootapp
at org.hibernate.tuple.component.ComponentTuplizerFactory.constructTuplizer(ComponentTuplizerFactory.java:104) ~[hibernate-core-5.4.10.Final.jar!/:5.4.10.Final] springbootapp
... 46 common frames omitted springbootapp
Caused by: org.hibernate.PropertyNotFoundException: Could not locate field name [official] on class [hello.world.entity.Country]

最佳答案

仅需要 @IdClass@EmbeddedId 方法之一。此外,@IdClass 是错误的,因为嵌入 id 的类是 CountryLanguage。此外,使用 @Id@Column 注释的 Country 上的 code 字段也与 code 冲突CountryLanguage 上的 > 字段,用 @Column 注释。

对于 @EmbeddedId 方法,应将 @IdClass 注释与 code 上的 @Id 一起删除解决问题。

关于java - 由 : org. hibernate.PropertyNotFoundException 引起:无法在类上找到字段名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60053957/

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