Hibernate - How to persist only the parent, keeping the children as they are

前端 未结 3 836
我寻月下人不归
我寻月下人不归 2020-12-09 12:57

Can someone please help me understand how to configure hibernate to do what i want.

I have a parent entity \"Appartment\" with a List of \"Room\"s as children. I hav

3条回答
  •  失恋的感觉
    2020-12-09 13:43

    This is really simple. No need to repopulate your children, or create separate DTO's.

    If you are never going to persist the children just add insertable=false, updatable=false to your joincolumn annotation. Like this:

    @OneToMany
    @JoinColumn (name = "appartmentId", insertable = false, updatable = false)
    @Fetch(value = FetchMode.JOIN)
    private List room;
    

提交回复
热议问题