I am integrating a project with Spring, using Hibernate JPA and within the relations that are inside I have an error because the attribute is not being assigned correctly, I am new to using JPA to be relating the tables
child class where it is planned to have the foreign key inside the attributes
@Entity
@Table(name = "tipo_credito")
public class Credito {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(name = "nombre", nullable = false, length = 50)
private String nombre_evento;
@ManyToOne
private Events id_eventos;
public Credito() {
}
**parent class**
@Entity
@Table(name = "eventos")
public class Events {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(name = "nombre", nullable = false, length = 50)
private String name;
@Column(name = "fecha", nullable = false, length = 50)
private Date date;
@ManyToOne(targetEntity = Validacion.class)
private Validacion id_validacion;
@ManyToOne(targetEntity = PlanEstudios.class)
private PlanEstudios id_plan_estudios;
@OneToMany(mappedBy = "eventos", cascade =CascadeType.ALL, orphanRemoval=true)
private List<Credito> id_credito;
@Column(name = "horas", nullable = false, length = 50)
private int horas;
public Events() {
}
Likewise, I have an error to assign an entity, it is not correctly defined, so creating it is becoming a complicated task
I solved it by referring to the same name of the variable that we are passing, that is, the variable that, for example, is in the ManyToOne, which is id_eventos, must be the same variable that I have in the events class created, that is, in the events class, I must mate this event_id variable