79657046

Date: 2025-06-07 14:32:40
Score: 2
Natty:
Report link

Given your setup and the JSON you're working with, it seems the problem arises from the way you're managing the client and service references prior to saving the Turno. JPA won't automatically handle those relationships just based on IDs in nested objects. When you only include the IDs (like { "id": 1 }) in your request, Spring can't figure out how to convert these into managed entities unless you do it yourself. The fix? Before you save the Turno, retrieve the Cliente and Servicio from the database and link them to the Turno. For example:

Cliente cliente = clienteRepository.findById(turno.getCliente().getId()).orElseThrow();
Servicio servicio = servicioRepository.findById(turno.getServicio().getId()).orElseThrow();
turno.setCliente(cliente);
turno.setServicio(servicio);
turnoRepository.save(turno);

This makes sure that Turno points to the right entities, and JPA will handle the foreign keys without a hitch.

Reasons:
  • RegEx Blacklisted phrase (1.5): fix?
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Contains question mark (0.5):
  • Low reputation (1):
Posted by: Hotdev