java hibernate entity: allow to set related object both by id and object itself

前端 未结 3 1396
野趣味
野趣味 2021-02-05 17:18

I\'ve got a following Java class which is also a Hibernate entity:

@Entity
@Table(name = \"category\")
public class Category {

    @ManyToOne
    @JoinColumn(na         


        
3条回答
  •  心在旅途
    2021-02-05 17:58

    You can define lazy init

    @ManyToOne(fetch=FetchType.LAZY)
    

    guess the column is nullable so it's not a problem to save the Category without parent (root)

提交回复
热议问题