I'm new to Angular and I have the following situation using the API in java:
I have the "Launch" class where the NOT category is mandatory (Category class)
@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;
(...)
}
/ p>
{"descricao":"teste","categoria":{}}
But my API returns the following error (in java) due to not having reported the category:
TransientObjectException - object references an unsaved transient instance - save the transient instance before flushing
I ran a Postman test by submitting the JSON as follows to register the release:
{"descricao":"teste"}
In this way I can register, then there is the doubt:
The error is in the angle that is 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 is the error in the category declaration in the class class?
When you register the release by reporting the category, there are no errors and JSON is sent as follows:
{"descricao":"teste","categoria":{"codigo":1}}