I’ve created a table like this:
CREATE TABLE employee (
id int(11) NOT NULL AUTO_INCREMENT,
first_name varchar(45) DEFAULT NULL,
last_name varchar(45) DEFAULT NULL,
PRIMARY KEY(id)
)
as You see, I’ve used: AUTO_INCREMENT
Then Why should I use @GeneratedValue in my Entity Class while I’ve specified auto increment in the definition of table to make it self-incremental?
My Entitiy Class:
@Entity
@Table(name = "employee")
public class Employee{
@Id
@Column(name = "id")
@GeneratedValue(strategy=GenerationType.IDENTITY)
private int id;
@Column(name = "first_name")
private String firstName;
@Column(name = "last_name")
private String lastName;
.
.
.
}
if database is going to generate primary key, then why should I specify the way of generation of primary key in entity class?
who generates foreign key? hibernate or database?