Cześć,
Chcę zapisać 2 adresy do bazy danych w następujący sposób:
public int[] saveAddressToDB(final List<Address> addressesFromForm) {
List<Address> adressesList = addressesFromForm;
for(Address add : adressesList){
if (add.getIdEmployee() == null) {
add.setIdEmployee(employeeRepository.getIdEmployeeKey());
}
}
System.out.println(adressesList);
final String INSERT_EMP_QUERY = "INSERT INTO Address (id_employee, type, street, street_nr, flat_nr, postal_code, city, country) VALUES (?, ?, ?, ?, ?, ?, ?, ?)";
List<Object[]> empList = new ArrayList<Object[]>();
for(Address addr : adressesList) {
Object[] values = new Object[] {
addr.getIdEmployee(),
addr.getType(),
addr.getStreet(),
addr.getStreetNr(),
addr.getFlatNr(),
addr.getPostalCode(),
addr.getCity(),
addr.getCountry()
};
empList.add(values);
System.out.println(values + "values");
}
return this.jdbcTemplate.batchUpdate(INSERT_EMP_QUERY, empList);
}
Wrzuciłem 2 printy. W jednym jak i drugim przypadku listy są pełne. Pomimo tego po wykonaniu metody, adresy nie zapisują się w bazie danych, a konsola nie zwraca żadnego błędu.