Generating correct json with p-dropdown primeng?

Asked

Viewed 105 times

0

I’m new to Angular and I’m in the following situation using the API java:

I have the class "Lancamento" where the category NAY is mandatory (class Category)

@Entity
@Table(name = "lancamento")
public class Lancamento {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long codigo;

    @NotNull
    private String descricao;

    @ManyToOne
    @JoinColumn(name = "codigo_categoria")
    private Categoria categoria;

    (...)
}

When I will register a release on the page created with Angular using the REST API, sending the JSON for this API as follows:

{"descricao":"teste","categoria":{}}

But mine API returns the following error (in java) due to not having informed the category:

TransientObjectException - object references an unsaved transient instance - save the transient instance before flushing

I ran a test on Postman sending the JSON as follows to register the launch:

{"descricao":"teste"}

This way I can register, then the doubt:

The error is at the angle using the component p-dropdown of primeng as follows:

    <p-dropdown placeholder="Selecione..." [autoWidth]="false"
      [filter]="true" [options]="categorias"
      [(ngModel)]="lancamento.categoria.codigo" name="categoria"
      #categoria="ngModel"></p-dropdown>

Or the error is in the category declaration in the class release?

When I register the release stating the category, there are no errors and the JSON is sent as follows:

{"descricao":"teste","categoria":{"codigo":1}}

1 answer

0

Browser other questions tagged

You are not signed in. Login or sign up in order to post.