我正在尝试保留List,但是我收到此错误
org.hibernate.MappingException: Could not determine type for: java.util.List, at table: Person, for columns: [org.hibernate.mapping.Column(comments)]
我已经使用了hibernate文档中指定的@ElementCollection注释。我看不出还有什么可以尝试。
请忽略此段仅是必需的,以便我可以提交问题。
import java.util.ArrayList;
import java.util.List;
import javax.persistence.Column;
import javax.persistence.ElementCollection;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import org.hibernate.annotations.GenericGenerator;
import org.springframework.stereotype.Component;
@Component
@Entity
public class Person {
private String name;
private Long id;
private String reviewName;
private String review;
private List<String> comments = new ArrayList<String>();
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Id
@GeneratedValue(generator="increment")
@GenericGenerator(name="increment", strategy="increment")
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
@Column(columnDefinition="LONGTEXT")
public String getReview() {
return review;
}
public void setReview(String review) {
this.review = review;
}
public String getReviewName() {
return reviewName;
}
public void setReviewName(String reviewName) {
this.reviewName = reviewName;
}
public List<String> getComments() {
return comments;
}
@ElementCollection
public void setComments(List<String> comments) {
this.comments = comments;
}
public void addComment(String comment) {
getComments().add(comment);
}
}
答案 0 :(得分:0)
@elementcollection注释应该放在getter(getComments())而不是setter
答案 1 :(得分:0)
问题是你应该
@ElementCollection(targetClass=String.class)
在每次提及集合类型(map / list / etc)之前,包括属性声明和方法声明。
不是在提及之前#34;而不是&#34;另一个,但无处不在。