出现以下异常,为什么我不知道,请帮我解决它
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/