One to Many Mapping Springboot Jpa

 

One to Many and Many to One Mappin in Springboot models


One to Many and Many to One relation b/w OrderDetail and Product means one OrderDetail can have multiple products and Many Products can contain one product detail




OrderDetail Model
@Entity
@Data
@AllArgsConstructor
@NoArgsConstructor
@ToString
public class OrderDetails {
@Id
@GeneratedValue
private int id;
private int orderId;
private int productId;
private double orderPrice;
private int productQuantity;
@OneToMany(mappedBy = "orderDetails")
private List<Product> productsOrderDetail;
}
Product model

@Entity
@Data
@AllArgsConstructor
@NoArgsConstructor
@ToString
public class Product {
@Id
@GeneratedValue
private int id;
private String productName;
private double productPrice;
private int productQuantity;
@ManyToOne
@JoinColumn(name = "productsOrderDetail")
private OrderDetails orderDetails;
}

Comments

Popular Posts