I\'m creating a simple app to just insert a row to a table (if table does not exist, create it) using Java JPA
.
I\'m attaching some code for a runnable exam
Try with the below code then, it will allow you to set the ID
manually.
Just use the @Id
annotation which lets you define which property is the identifier of your entity. You don't need to use the @GeneratedValue
annotation if you do not want hibernate to generate this property for you.
assigned - lets the application to assign an identifier to the object before save()
is called. This is the default strategy if no
element is specified.
package view;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table(name = "People")
public class Person {
@Id
//@GeneratedValue(strategy = GenerationType.AUTO) // commented for manually set the id
private int id;
private String name;
private String lastName;
public Person(int id, String name, String lastName) {
this.id = id;
this.name = name;
this.lastName = lastName;
}
public Person() {
}
}