1
I’m trying to make a phone call Many-to-Many
between classes usuario
and permissao
, using the documentation of Hibernate as reference . But when I try to generate a class JSON file usuario
the program loops and generates an unexpected file.
How to avoid this and do with it limit the output file.
I’m using the Spring Boot 2.0.2
Below are my classes:
Usuario Class.
public class Usuario {
protected long id;
protected String nome;
private String senha;
@ManyToMany(cascade = {CascadeType.PERSIST, CascadeType.MERGE})
private List<Permissao> permissao;
}
Permission.class
public class Permissao{
protected long id;
protected String nome;
@ManyToMany(mappedBy = "permissao")
private List<Usuario> usuario;
}
SQL(Constraints have been removed for simplification)
CREATE TABLE usuario
(
id INT UNSIGNED AUTO_INCREMENT
PRIMARY KEY,
nome VARCHAR(45) NOT NULL,
senha VARCHAR(45) NOT NULL
)
CREATE TABLE usuario_permissao
(
usuario_id INT(11) UNSIGNED NOT NULL,
permissao_id INT(11) UNSIGNED NOT NULL
)
CREATE TABLE permissao
(
id INT UNSIGNED AUTO_INCREMENT
PRIMARY KEY,
nome VARCHAR(45) NOT NULL
)
and the json output
[{"id":1,"nome":"admin","senha":"admin","permissao":
[{"id":1,"nome":"admin","usuario":
[{"id":1,"nome":"admin","senha":"admin","permissao":
[{"id":1,"nome":"admin","usuario":
[{"id":1,"nome":"admin","senha":"admin","permissao":
[{"id":1,"nome":"admin","usuario":
[{"id":1,"nome":"admin","senha":"admin","permissao":
[{"id":1,"nome":"admin","usuario":