0
I’m creating an api using Java with Springboot, and Ibernate. The idea is to save guests in the database, and these guests have a group, I don’t really understand the notes, but Mapeei with @Manytoone
@Entity
@Table(name = "con_convidado")
public class Convidado {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Length(max = 20)
private String nome;
@Enumerated(EnumType.STRING)
private Gender genero;
@ManyToOne(cascade = CascadeType.ALL)
private Grupo grupo;
@Enumerated(EnumType.STRING)
private Age faixaEtaria;
public Convidado() {
}
Everything is working normally, but when I enter guests with the same group, in the database it creates a new line, and gets repeated information.
Group Class
@Entity
public class Grupo {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String nome;
How to reuse what is already on the table, or improve the relationship between them.
maybe this post will help you https://answall.com/questions/234755/diferen%C3%A7as-onetomany-manytomany-manytoone-onetoone, but I think the Join column is missing.
– Scarabelo
You are sending the group with the completed existing id?
– Leonardo Lima
No, I’m sending it back in the requisition form, but I had seen somewhere that the data was not repeated
– BrunoFow