0
我已經在數據庫(PostgreSQL)中創建了一個序列,並且在域模型中有以下注釋。我正在使用JPA。但是,當我在要創建的對象中調用沒有ID的Web服務(REST)時會引發約束錯誤。但是,它不應該使用以下序列中的值嗎?JPA不使用序列
@Id
@SequenceGenerator(name = "user_seq", sequenceName = "user_seq", allocationSize = 1)
@GeneratedValue(strategy = GenerationType.IDENTITY, generator = "user_seq")
private int id;
Caused by: org.hibernate.exception.ConstraintViolationException: could not execute statement Caused by: org.postgresql.util.PSQLException: ERROR: null value in column "id" violates not-null constraint
真棒,感謝您的發現。我在其他類中編寫了SEQUENCE。例如,如果您在MySQL中使用自動遞增列值,IDENTITY是否使用正確的類型?我不明白API中的解釋。 – LuckyLuke
歡迎。是的,身份是MySQL自動增量的正確選擇。 –