First you should not use the same id for any object. I would suggest to add the @GeneratedValue annotation for the primary key. I have create the entity with Lombok like that:
@Entity
@Data
@NoArgsConstructor
class Employee {
@Id
@GeneratedValue
private Integer id;
private String name;
private Timestamp effectiveFrom;
public Employee(String name, String effectiveFrom) {
this.name = name;
this.effectiveFrom = effectiveFrom == null ? null : Timestamp.valueOf(effectiveFrom);
}
}
At the end I create a simple jpa repository and save all entities:
@Bean
CommandLineRunner run(EmployeeRepository employeeRepository) {
return args -> {
List<Employee> employees = List.of(new Employee("Employee1", "2019-10-10 00:00:00.000"),
new Employee("Employee2", null), new Employee("Employee3", "2019-10-10 00:00:00.000"),
new Employee("Employee4", "2019-10-10 00:00:00.000"));
employeeRepository.saveAll(employees);
employeeRepository.findAll().forEach(System.out::println);
};
}
The console output looks like that:
Employee(id=1, name=Employee1, effectiveFrom=2019-10-10 00:00:00.0)
Employee(id=2, name=Employee2, effectiveFrom=null)
Employee(id=3, name=Employee3, effectiveFrom=2019-10-10 00:00:00.0)
Employee(id=4, name=Employee4, effectiveFrom=2019-10-10 00:00:00.0)
Please have a look at this short example. If you cannot find the error in your code, please post your code so I can have a look.