@Entity
@NamedEntityGraph(
name = "CustomersWithOrderId",
includeAllAttributes=false,
attributeNodes = {
@NamedAttributeNode(value = "name"),
@NamedAttributeNode(value = "orders", subgraph = "ordersGraph")
},
subgraphs = {
@NamedSubgraph(
name = "ordersGraph",
type = OrderEntity.class,
attributeNodes = {
@NamedAttributeNode(value = "id"),
@NamedAttributeNode(value = "campaignId")
}
)
}
)
public class CustomerEntity {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "customer_seq")
@SequenceGenerator(name = "customer_seq", sequenceName = "CUSTOMER_SEQ_ID_SEQ", allocationSize = 1)
private long id;
@Column
private String name;
@Column
private int numberOfPurchases;
@OneToMany(mappedBy = "customer", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
private Set<OrderEntity> orders;
@OneToMany(mappedBy = "customer", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
private Set<AddressEntity> addresses;