我有下一个型号:
清单实体:
@Getter
@Setter
@Entity
@Table(name = "shipping_manifest")
public class Manifest {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(nullable = false)
private Long id;
// other fields
@OneToMany(cascade = {CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REFRESH}, mappedBy = "manifest")
// @OrderBy("appOrder.orderNO")
@Column(nullable = false)
private Set<ShippingLabel> labels;
}
标签实体:
@Getter
@Setter
@Entity
@Table(name = "shipping_label")
public class ShippingLabel {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(nullable = false)
private Long id;
// other fields
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "manifest_id", nullable = false)
private Manifest manifest;
@OneToOne(cascade = {CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REFRESH} , fetch = FetchType.LAZY)
@JoinColumn(name = "order_id")
private Order appOrder;
}
订单实体:
@Getter
@Setter
@Entity
@Table(name = "app_order")
public class Order {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(nullable = false)
private Long id;
@Column(name = "order_no", nullable = false)
private Long orderNO;
// other fields
@OneToOne(mappedBy = "appOrder")
private ShippingLabel label;
}
是否有可能通过订单实体的orderNO feild从订购的ShippingLabels获取Manifest实体?
我在javadoc中读到有关@OrderBy
注释的内容,但它只允许对Embadded字段使用点符号。
P.S。我使用Spring Data和Hibernate作为JPA实现。