I have a requirement in which I have to store a new record in the table with the ID that I send manually. Now in my hibernate entity file I use @SequenceGenerator and @GeneratedValue, so when i try to save, even though I try passing a ID I am getting a new ID being generated. I need to know if there is any way that we have where when we pass Id to the entity the new sequence not be created but the new record will be created with the id that is being passed to the entity. Given below is my Entity
Subject.java
@Entity
@Table(name = "SUBJECT")
public class Subject {
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "SEQ")
@SequenceGenerator(name = "SEQ", sequenceName = "SUBJECT_SEQ", allocationSize = 1)
@Column(name = "ID")
@Id
private int id;
@ManyToOne
@JsonIgnore
@JoinTable(name = "STUDENT_SUBJECT", joinColumns = { @JoinColumn(name = "SUBJECT_ID") }, inverseJoinColumns = { @JoinColumn(name = "STUDENT_ID")})
private Consignee consignee;
@Column(name="SUBJECT_NAME")
private String subjectName;
//Getters and Setters
}