If I don't want to automatically generate the primary Key, instead, I want to supply the ID with the first column of the table as primary key.
2 A
4 B
7 D
13 E
...
I want the first column 2,4, 7, 13 to be the primary key of the table. Should I just use @Id to do the annotation?
@Entity
public class Code {
@Id
@Column(unique=true)
private int id;
...
}
Or, if @Id is used, the primary key will be always automatically generated, instead of using the first column, in this case?
@Id
will only declare the primary key. it will not insert generated value. if you use @GeneratedValue
then it will generate the value of the field.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With