3

I need next functional. Below value

@Column(name = "incomeNumber", unique = true, nullable = false)
    private int incomeNumber;

must start from 1 and be auto increment. How i can set this with hibernate ?

O.Kuz
  • 377
  • 3
  • 5
  • 18

2 Answers2

1

you can do this. Also can delegate the increment to sequence in db

@GenericGenerator(name="incgenerator" , strategy="increment")
@GeneratedValue(generator="incgenerator")
@Column(name = "incomeNumber", unique = true, nullable = false)
    private int incomeNumber;
D. Pineda
  • 66
  • 2
0

Follow D. Pineda idea plus add an default value if you whant it start at 1; Setting default values for columns in JPA

Community
  • 1
  • 1
Zorglube
  • 664
  • 1
  • 7
  • 15