gpt4 book ai didi

java - 在 Hibernate 中将集合中的映射异常另存为成员变量

转载 作者:行者123 更新时间:2023-11-30 08:09:26 24 4
gpt4 key购买 nike

出现以下异常,为什么我不知道,请帮我解决它

Exception in thread "main" org.hibernate.MappingException: Could not determine type for: java.util.List, at table: USER_DETAIL, for columns: [org.hibernate.mapping.Column(listOfAddress)]

 @Entity 
@Table (name="USER_DETAIL")
public class UsersDetail {

private int id; //
@Column (name ="NAME")
private String name;
@ElementCollection
private List<Address> listOfAddress = new ArrayList<Address>();


@Id @GeneratedValue
@Column (name ="ID")
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public List<Address> getListOfAddress() {
return listOfAddress;
}
public void setListOfAddress(List<Address> listOfAddress) {
this.listOfAddress = listOfAddress;
}}

最佳答案

您好,我认为问题出在注释的位置上。您正在使用方法访问策略(由@Id注释确定)。将任何与 JPA 相关的注释放在每个 getter 的正上方,而不是字段成员的上方。

如下:-

@Column (name ="NAME")
public String getName() {
return name;
}

@ElementCollection
public List<Address> getListOfAddress() {
return listOfAddress;
}

关于java - 在 Hibernate 中将集合中的映射异常另存为成员变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30611446/

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