Issue
Am i right that @Id annotation add two constraints in database:
- nullable=false
- unique=true
? I saw a lot of examples in the Internet with syntax like
@Id
@Column(name="xxx",nullable=false)
BigInteger id
It is correct? Do i really need this nullable=false?
Solution
Yes you are right. If you use hibernate schema generation mechanism, all @Id columns in the database will be NOT NULL and have unique index by default.
In the other hand, @Column(nullable=false)
declaration is absolutely meaningless if you create the schema any other way.
Answered By - Alex Bondarev