【发布时间】:2021-12-01 11:26:10
【问题描述】:
是否可以像在 Spring Data JPA 中一样在 Spring Data Jdbc 中为 OneToMany 和 ManyToMany 关系级联创建?如果不是,那么策略是什么?
@Table("orders")
public class Order {
@Id private UUID id;
@MappedCollection(idColumn = "order_id")
private Set<OrderItem> orderItems = new HashSet<>();
private LocalDateTime lastModifiedDateTime;
public Order() {}
}
@Table("orders_items")
public class OrderItem {
private UUID productId;
private Integer quantity;
@Transient private Product product;
public OrderItem(Product product, Integer quantity) {
this.productId = product.getId();
this.quantity = quantity;
}
}
@Table("products")
public class Product {
@Id private UUID id;
private String title;
private String description;
private BigDecimal price;
private LocalDateTime lastModifiedDateTime;
public Product(String title, String description, BigDecimal price) {
this.id = id;
this.title = title;
this.description = description;
this.price = price;
}
}
【问题讨论】:
标签: spring-boot spring-data-jdbc