What is the difference between @ManyToOne(optional=false) vs. @Column(nullable=false)

@Column(nullable=false) is an instruction for generating the schema. The database column generated off the class will be marked not nullable in the actual database.

optional=false is a runtime instruction. The primary functional thing it does is related to Lazy Loading. You can’t lazy load a non-collection mapped entity unless you remember to set optional=false (because Hibernate doesn’t know if there should be a proxy there or a null, unless you tell it nulls are impossible, so it can generate a proxy.)

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)