2 回答

TA貢獻(xiàn)1853條經(jīng)驗(yàn) 獲得超6個(gè)贊
您需要在 @id 旁邊添加 @GeneratedValue 注釋
@Id
@GeneratedValue(strategy = GenerationType.selectOne)
private long id;
在序列的情況下,您需要添加一個(gè)額外的注釋
@Id
@SequenceGenerator(name = "customName", sequenceName = "sequenceNameInDatabase")
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator="customName")
private long id;

TA貢獻(xiàn)1794條經(jīng)驗(yàn) 獲得超8個(gè)贊
這將使主 ID 生成自動
@Entity
@Table(name = "user")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class User implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
添加回答
舉報(bào)