I have build a small application on SPring MVC + JPA + SQL Server. For some reasons I had to make some Entity changes in my application and I had to manually migrate some data from old Database to new Database(that have a bit different schema). After I migrated all the data I have such errors:
13:47:26.191 [http-nio-8080-exec-1] ERROR o.h.e.jdbc.spi.SqlExceptionHelper - Violation of PRIMARY KEY constraint 'PK__GLJourna__3213E83F741BD595'. Cannot insert duplicate key in object 'dbo.GLEntry'. The duplicate key value is (34903).
This is my entity:
@Entity
public class GLJournalEntry {
@Id @GeneratedValue
private Long id;
private BigDecimal amount;
private Date creationDate;
@OneToOne
@JoinColumn(name = "glAccount_id", nullable = false)
private GLAccount glAccount;
private String notes;
@Enumerated(EnumType.STRING)
private ProductType productTyep;
private Date entryDate;
@Column(nullable = false)
private long transactionID;
@Enumerated(EnumType.STRING)
private EntryType type;
}
My guess is that I receive this error message because of default ID annotation @Id @GeneratedValue.
How can I fix it? how can I generate ID in a way that it automatically got the latest ID from DB?