Java 如何在Hibernate Spring中级联CollectionElement
我写了以下对象:Java 如何在Hibernate Spring中级联CollectionElement,java,spring,hibernate,jpa,Java,Spring,Hibernate,Jpa,我写了以下对象: @Entity public class Report implements Serializable { @Id private String url; @LazyCollection(LazyCollectionOption.FALSE) @ElementCollection() private List<ArrayList<KeyPhrase>> keywordReports = new ArrayList<>(); @Lazy
@Entity
public class Report implements Serializable {
@Id
private String url;
@LazyCollection(LazyCollectionOption.FALSE)
@ElementCollection()
private List<ArrayList<KeyPhrase>> keywordReports = new ArrayList<>();
@LazyCollection(LazyCollectionOption.FALSE)
@ElementCollection()
private List<KeyPhrase> allKeyPhrases = new ArrayList<>();
@LazyCollection(LazyCollectionOption.FALSE)
@ElementCollection()
private List<KeyPhrase> allOtherPhrases = new ArrayList<>();
@LazyCollection(LazyCollectionOption.FALSE)
@ElementCollection()
private List<KeyPhrase> topGroup = new ArrayList<>();
public Report(String url, List<ArrayList<KeyPhrase>> keywordReports, List<KeyPhrase> allKeyPhrases,
List<KeyPhrase> allOtherPhrases, List<KeyPhrase> topGroup) {
this.url = url;
this.keywordReports = keywordReports;
this.allKeyPhrases = allKeyPhrases;
this.allOtherPhrases = allOtherPhrases;
this.topGroup = topGroup;
}
}
我已经读到错误消息指出了一个问题,可以通过添加CASCADE.ALL注释来解决。然而,对于我正在使用的注释,我不知道在哪里指定级联。我尝试了几个注释,但编译器总是告诉我指定级联是非法的
我还尝试添加此批注,但未成功:
"@Cascade(org.hibernate.annotations.CascadeType.ALL)"
仅供参考,我在项目中还有另一个实体,我在其中完成了以下工作:
@LazyCollection(LazyCollectionOption.FALSE)
@ElementCollection()
private List<String> related = new ArrayList<>();
@LazyCollection(LazyCollectionOption.FALSE)
@ElementCollection()
private List related=new ArrayList();
有趣的是,这个很有魅力
谁能给我一个提示,我如何解决级联问题,或者我的代码还有什么问题
提前谢谢 您必须指定报表与关键字短语之间的关系。像
1.
@OneToOne
2.
@OneToMany
3.
@manytomy
执行此操作时,可以指定级联属性。比如说
@OneToMany(cascade = {CascadeType.ALL})
private List<KeyPhrase> allKeyPhrases = new ArrayList<>();
@OneToMany(cascade={CascadeType.ALL})
private List allkeyphases=new ArrayList();
Hi@pvpkiran,谢谢你的评论。我尝试了这个,但我得到了一个错误,因为关键字列表没有映射。我想这就是ElementCollection的目的——您不必映射子元素,只需通过父元素使用它们,而不必进行n对n注释?
@OneToMany(cascade = {CascadeType.ALL})
private List<KeyPhrase> allKeyPhrases = new ArrayList<>();