I have a product table
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Entity
public class Product extends AuditModel {
@Id
@SequenceGenerator(name="optimized-sequence",sequenceName = "seq_product")
private Integer id;
private String sku;
private String description;
@NotNull
private String name;
***
***
***
@ManyToOne(optional = true)
@JoinColumn(name = "category_id")
@OnDelete(action = OnDeleteAction.NO_ACTION)
private Category category;
@ManyToOne(optional = true)
@JoinColumn(name = "manufacturer_id")
@OnDelete(action = OnDeleteAction.NO_ACTION)
private Manufacturer manufacturer;
@OneToMany(mappedBy = "product")
private List<OrderProduct> orderProducts;
}
And a CrudRepository
public interface ProductRepository extends PagingAndSortingRepository<Product, Integer> {
Product findFirstBydescription(@Param("description")String description);
}
when i call the endpoint /products by default I get a list of all products like this
{
"_embedded" : {
"products" : [ {
"createdAt" : "2019-11-15T08:56:23.393+0000",
"updatedAt" : "2019-11-15T08:56:23.393+0000",
"id" : 802,
"sku" : null,
"name" : " product 1",
"description" : "description one",
"_links" : {
"self" : {
"href" : "http://localhost:8080/api/products/802"
},
"product" : {
"href" : "http://localhost:8080/api/products/802{?projection}",
"templated" : true
},
"manufacturer" : {
"href" : "http://localhost:8080/api/products/802/manufacturer"
},
"orderProducts" : {
"href" : "http://localhost:8080/api/products/802/orderProducts"
},
"category" : {
"href" : "http://localhost:8080/api/products/802/category"
}
}
}, .......
How can I get, calling the default endpoint /products, inside the json object product the related objects too (Catefory, Manufacturer...)?
Thanks