How to make a @ManyToOne field mandatory in JPA2?

后端 未结 3 687
我在风中等你
我在风中等你 2021-01-20 07:40

I am designing the persistence repository for an app.

I am new to Hibernate+JPA2 and I am having trouble creating more complex relationships

相关标签:
3条回答
  • 2021-01-20 08:11

    You have to use @JoinColumn(name=..., nullable=false) not @Column

    See the complete API

    0 讨论(0)
  • 2021-01-20 08:17

    Or you can just use @NotNull from javax.validations.constraints package.

    0 讨论(0)
  • 2021-01-20 08:17

    It should be enough to just use @ManyToOne(optional = false)

    0 讨论(0)
提交回复
热议问题