I am using spring framework in my product class there is @OneToMany relationship between product and productReview So I mapped this relation as follows but when I called findAll() method of products it gives me an error of Bad String
I cant figure out what is the problem , when I removed @OneToMany relation it runs perfectly
Product.java
@Entity
@Table(name="products")
public class Product implements Serializable{
private static final long serialVersionUID = 1L;
@Id
@SequenceGenerator(name="SEQ_PRODUCTS", sequenceName="PRODUCTS_SEQ", allocationSize=1)
@GeneratedValue(strategy=GenerationType.SEQUENCE, generator="SEQ_PRODUCTS")
private Long id;
@NotEmpty
@Column(name="NAME", nullable=false)
private String name;
@ManyToMany
private List<ProductImages> productImages;
@OneToMany(mappedBy="product",targetEntity=ProductReview.class,fetch = FetchType.EAGER,cascade = CascadeType.ALL)
private List <ProductReview> productReviews;
..... Getter and setter of above fields
}
ProductReview.class
@Entity
public class ProductReview implements Serializable {
private static final long serialVersionUID = 1L;
@GeneratedValue(strategy=GenerationType.AUTO)
@Id
private Long id;
private String title;
private String message;
private Double rating;
@ManyToOne
private Product product;
..... Getter and setter
}
API : http://localhost:8080/api/products
Response : Bad String
List <ProductReview> productReviews, because you can always queryProductReviewtable if you need this info - varren