i am new in spring boot and i could not find solution for this for a day now.
@GetMapping used to retrive item gives a responce of infinite loop of foreignkey object "user".
why am i getting this infinite loop?
how to fix it?
user object in infinite loop(the problem)
result that i want
item entity
@Entity
public class Item{
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long ItemId;
@ManyToOne
@JoinColumn(name = "owner_id")
private User user;
private String ItemName;
// @Column(columnDefinition="text")
private String Description;
private double Price;
private int AvailableQuantity;
private double shippingWeight;
// @Transient
// private MultipartFile Picture;
@Enumerated(value = EnumType.STRING)
private Category category;
@OneToMany(mappedBy = "item")
@JsonIgnore
private List<CartItem> CartItemList;
}
user entity
@Entity
@Table(name = "Utilisateur")
public class User {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long idU;
private String username;
private String password;
private String firstname;
private String lastname;
private String gender;
private Long phone;
private String adress;
@Temporal(TemporalType.DATE)
private Date dateofbirth;
private int rating;
private String email;
public Role role;
private Integer status;
@OneToMany(mappedBy = "user")
private List<Item> ItemList;
}
item service
@Service
public class ItemService implements ItemServiceInterface{
@Autowired
ItemRepository itemrepository;
public Optional<Item> getItemById(long id){
return itemrepository.findById(id);
}
}
item controller
@RestController
public class ItemControl {
@Autowired
ItemServiceInterface itemservice;
@GetMapping("/getitem/{id}")
public Optional<Item> getitembyid(@PathVariable Long id) {
return itemservice.getItemById(id);
}
}