I recently started learning Angular and encountered a situation while using the Java API:
In my Release
class, the category is not required (class Category).
@Entity
@Table(name = "release")
public class Release {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@NotNull
private String description;
@ManyToOne
@JoinColumn(name = "id_category")
private Category;
(...)
}
When attempting to register a release through an Angular-created page using the REST API, I send the following json
:
{"description": "test", "category": {}}
Since the category is not provided, my API in Java returns the error:
TransientObjectException - object references an unsaved transient instance - save the transient instance before flushing
To test this, I used Postman and successfully registered a release without specifying the category as follows:
{"description": "test"}
This leads me to question whether the issue lies in the Angular code that utilizes the p-dropdown
component from PrimeNG
:
<p-dropdown placeholder="Select ..." [autoWidth]="false"
[filter]="true" [options]="categories"
[(ngModel)]="release.category.id" name="category"
#category="ngModel"> </p-dropdown>
Or could it be related to how the category is declared in the Release class?
Upon registering a release with the specified category, there are no errors and the json
looks like this:
{"description": "test", "category": {"id": 1}}
Any insights would be appreciated. Thank you!