Java Persistence / JPA: @Column vs @Basic

后端 未结 4 784
一整个雨季
一整个雨季 2020-12-22 17:31

What is the difference between @Column and @Basic annotations in JPA? Can they be used together? Should they be used together? Or does one

4条回答
  •  情深已故
    2020-12-22 18:15

    The @Basic annotation are applied to JPA entities, and the of @Column are applied to the database columns @Basic annotation's optional attribute defines whether the entity field can be null or not; on the other hand,

    • @Column annotation's nullable attribute specifies whether the corresponding database column can be null
    • We can use @Basic to indicate that a field should be lazily loaded
    • The @Column annotation allows us to specify the name of the mapped database column
    • @Basic annotation marks the property as not optional on the Java object level. And (nullable = false) on the column mapping, is only responsible for the generation of a NOT NULL database constraint.

提交回复
热议问题