hi how I am currently doing a project with these technologies
- HIBERNATE (TO CREATE ENTITIES AND DEMAS)
- JPA (ETC. CONNECTIONS)
- JDBC (CONNECTIONS OF ANOTHER TYPE)
- SPRING MVC (TO CREATE THE DRIVER AND RETURN JSON)
The detail is that I have very little experience with hibernate ..
I currently have this kind of example in relations @onetomany
@Entity
public class Recetas implements Serializable {
@GeneratedValue(strategy = GenerationType.AUTO)
@Id
private int id;
private String Nombre;
private String imagenUrl;
private int minutos;
@OneToMany(mappedBy = "recetas_id")
private List<Ingredientes> ingredientes = new ArrayList<>();
that makes a relation with ingredients (since a recipe can have several ingredients)
@Entity
public class Ingredientes {
@GeneratedValue(strategy = GenerationType.AUTO)
@Id
private int id;
private String nombre;
@ManyToOne
@JoinColumn(name = "recetas_id", nullable = false)
private Recetas recetas_id;
and I do a joincolumn for references to the father and have a bidirectional relationship of
The detail is that when I try to extract the data in json it makes me an infinite loop
because as you can see a father has a son and the son refers to the father .. and then a loop is made inward
{
"id": 1,
"nombre": "Huevos",
"recetas_id": {
"id": 1,
"imagenUrl": "http://google.com.mx",
"minutos": 10,
"ingredientes": [],
"nombre": "Huevos con chorizo "
}
}