且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

从级联删除连接表与@ManyToMany注解

更新时间:2023-02-05 11:38:49

您可以将您的@ManyToMany分成@一对多,多对一,并成立了级联样式如图所示的此处虽然问题使用Hibernate的会话,你可以使用JPA的EntityManager。或者使用新的JPA功能 @ElementCollection (仅JPA 2)来映射你的加入类。请参见这里如何。仅仅通过更换@ElementCollection Hibernate的@CollectionOfElements

You can split your @ManyToMany into a @OneToMany-ManyToOne and set up a cascading style as shown here Although the question uses Hibernate's session, you can use JPA EntityManager. Or use the new JPA feature @ElementCollection (Only JPA 2) to map your joined class. See here how to. Just replace Hibernate's @CollectionOfElements by @ElementCollection