I have created a customer table as below
CREATE TABLE customer (
id number(11) generated always as identity (start with 1 increment by 1),
first_name varchar(45) DEFAULT NULL,
last_name varchar(45) DEFAULT NULL,
email varchar(45) DEFAULT NULL,
PRIMARY KEY (id)
);
Now I want to map the table(Customer) and its field in hibernate. For mapping the primary key id of the table Customer, what kind of strategy (GeneratedType) do i need to use as below?
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name="id")
private int id;
I have tried using all the strategies (AUTO,IDENTITY,TABLE,SEQUENCE). But for this primary key defined in the table none of them is working.
Getting different types of error while saving the customer.
Please guide in defining the primary key in the entity class customer, so that I can save the customer successfully.
Try using
It retrieves a primary key, assigned by a database trigger, by selecting the row by some unique key and retrieving the primary key value.