1
I have the following Entity classes
Patients
@Entity
@Table(name = "pacientes", schema = "sau")
public class Pacientes implements Serializable {
private static final long serialVersionUID = 5776384003601026304L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Basic(optional = false)
@Column(name = "idPaciente")
private Long idPaciente;
@JoinColumn(name="idPessoa")
@ManyToOne(cascade = CascadeType.ALL)
private Pessoas pessoa;
@Column(name = "nomeResponsavel")
private String nomeResponsavel;
@Column(name = "cpfResponsavel")
private String cpfResponsavel;
public Pacientes() {
}
//gets and sets
}
people
@Entity
@Table(name = "pessoas", schema="glb")
public class Pessoas implements Serializable {
private static final long serialVersionUID = -4042023941980758267L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Basic(optional = false)
private Long idPessoa;
@Temporal(TemporalType.DATE)
private Date dataNascimento;
private String inscricaoEstadual;
private String inscricaoMunicipal;
private String nome;
public Pessoas() {
}
//gets and sets
}
People addresses
@Entity
@Table(name = "pessoas_enderecos" ,schema="glb")
public class PessoasEnderecos implements Serializable {
private static final long serialVersionUID = -2560542418318988673L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long idPessoaEndereco;
private String bloco;
private String cep;
private String numero;
@JoinColumn(name="idPessoa")
@ManyToOne(optional = false, cascade = CascadeType.ALL)
private Pessoas pessoa;
public PessoasEnderecos() {
}
//gets and sets
}
I am making a register of patients in which I have the following fields:
Name: Date of Birth: State Registration: Responsible Name: CPF Responsible for: Zip code: Block: Number:
However, when saving, I cannot save class data PessoasEnderecos
other data is recording normal.
I’m taking all the data from the screen so much that I debug the browser to see..
It shows no errors. Someone knows what I’m failing to do ??
I have the following methods
Controller class
@RequestMapping(method = RequestMethod.POST, value = "/pacientes")
public Pacientes cadastrarPacientes(@RequestBody Pacientes pac) {
return pacientesService.cadastrar(pac);
}
service class
public Pacientes cadastrar(Pacientes pacientes){
return pacRepository.save(pacientes);
}
Repository class
public interface PacientesRepository extends JpaRepository<Pacientes, Integer> {
}
I agree with you.. but that would change my database however I can’t change.. there would be some other alternative ?
– Eduardo Krakhecke
I don’t understand why this would change your base, but you can take the information Person, block, zip and number, set in a new Personal object and save through the save method of Personal Senderecos.
– Kevin Eduard Piske
I did by your answer and at the time of starting the application I had the following error
coluna pessoas0_.id_pessoa_endereco não existe
– Eduardo Krakhecke
Why are you trying to access the personal id_addresse_column in the personal 0_? table shouldn’t be personal.personal id_addresses_address?
– Kevin Eduard Piske