Hibernate cascading

血红的双手。 提交于 2019-12-06 11:31:11

Try putting the cascade annotation to the parent end of the mapping, like

@OneToMany(cascade = { CascadeType.PERSIST, 
                       CascadeType.MERGE, 
                       CascadeType.REMOVE },
           mappedBy = "children")
private Set<Children> children = new HashSet<Children>();

You may or may not need all those cascading options - pick your choice.

Here is a reference page just in case.

What you really need is

cascade=CascadeType.SAVE_UPDATE

But thats not part of JPA. So you can use this instead:

cascade=CascadeType.ALL

It will include SAVE_UPDATE (with the Hibernate implementation). But it may include other cascades you don't like.

You should combine JPA and Hibernate's private annotations. See documentation.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!