Hibernate @OneToOne @NotNull

后端 未结 3 1994
离开以前
离开以前 2020-12-15 08:33

Is it valid to declare @OneToOne and @NotNull on both sides of a relationship, such as:

class ChangeEntry
{
    @OneToOne(cascade=C         


        
3条回答
  •  难免孤独
    2020-12-15 08:44

    It should be persisting the transient value because of your cascade type.

    If you are actually trying to persist the first element before you've set the other transient element, then you'd expect this error.

    The constraint you've specified only specifies that the value cannot be null in the database, rather than in the data model, clearly when you construct a new instance of the object, the reference will be null. While the reference is null you cannot persist the entity.

提交回复
热议问题