1

I'm new to Micronaut, and have followed the documentation to set up a REST application, but I can't make a simple list from many to many. When starting the application everything looks normal, the database tables are being generated normally, and the terminal is returning the pageable entities, but it does not return the lists that are nested by the relationship for many.

@Entity
@Table(name = "unidade")
public class Unidade implements Serializable {

    private static final long serialVersionID = 1L;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer id;

    @NotNull
    private String nome;

    @NotNull
    private String cnpj;

    private String storage;

    private String telefone;

    @Email
    private String email;

    private boolean ativo;

    @ManyToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "empresa_id")
    private Empresa empresa;

    @ManyToMany(fetch = FetchType.LAZY)
    @JoinTable(name = "unidade_produto",
                joinColumns = @JoinColumn(name = "unidade_id"),
                inverseJoinColumns = @JoinColumn(name = "produto_id"))
    private List<Produto> produtos;
}
@Entity
@Table(name = "produto")
public class Produto implements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer id;

    @NotNull
    private String nome;

    @ManyToMany(mappedBy = "produtos")
    @JsonIgnore
    private List<Unidade> unidades;
}

POST Request:

{
    "nome": "Testando",
    "cnpj": "000.000.000/0000-01",
    "storage": "new",
    "telefone": "0000-0000",
    "email": "teste@gmail.com",
    "ativo": true,
    "empresa": {
        "id": 1
    },
    "produtos": [
        {
        "id": 1
        }
    ],
    "horario": {
        "id": 1
    }
            
}

There is no return from nesting entities. Could someone help me with this issue?

Adrian Mole
  • 49,934
  • 160
  • 51
  • 83

0 Answers0