I'm working on employees database. Each one of them needs to have it's unique employee number in 5 digit format. It doesn't have to, but can be corelated with id number in database. I was trying to create custom seter that will add auto generated id to number 00000, but it didn't worked. Now I'm trying to set @SequenceGenerator, but it doesn't work to.
the entity looks like this:
@Entity
@Table(name = "employees")
@NoArgsConstructor
@SequenceGenerator(name="empIdGen", initialValue=10, allocationSize=100)
@Data
public class EmployeeEntity {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@GeneratedValue(strategy=GenerationType.SEQUENCE, generator="empIdGen")
private int employeeId;
private String firstName;
private String lastName;
}
returnet JSON has 0 on that field for each employee:
[
{
"id": 1,
"employeeId": 0,
"firstName": "Jon1",
"lastName": "Doe1"
},
{
"id": 2,
"employeeId": 0,
"firstName": "Jon2",
"lastName": "Doe2"
},
{
"id": 3,
"employeeId": 0,
"firstName": "Jon3",
"lastName": "Doe3"
}
]
I expect values for field "employeeId" like 00001, 00002, 00003 or completly random, but unique. I would appreciate suggestions how to do that.