I am working on a Java EE project using hibernate, I am facing a class diagram similar to this one:
What I want to get is a list of customers who ordered a product. That means my named query has to get ID of the wanted product, and I want my named query to be writing on Customer class.
Can you help me in this one please?
Those are my classes :
@Entity
@Named Queries({
/* NAMED QUERY THAT I M LOOKING FOR */
})
public class customer implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Basic(optional = false)
@NotNull
@Column(name = "ID_CUSTOMER", nullable = false)
private Integer idCustomer;
@Size(max = 255)
@Column(name = "NAME", length = 255)
private String name;
@Size(max = 255)
@Column(name = "EMAIL", length = 255)
private String email;
@JoinColumn(name = "ID_ORDER", referencedColumnName = "ID_ORDER", nullable = true)
@ManyToOne(optional = false)
private GroupeAccess idOrder;
}
@Entity
public class order implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Basic(optional = false)
@NotNull
@Column(name = "ID_ORDER", nullable = false)
private Integer idOrder;
private Date date;
@JoinTable(name = "order_product", joinColumns = {
@JoinColumn(name = "ID_ORDER", referencedColumnName = "ID_ORDER", nullable = false)}, inverseJoinColumns = {
@JoinColumn(name = "ID_PRODUCT", referencedColumnName = "ID_PRODUCT", nullable = false)})
@ManyToMany
private Collection<product> productCollection;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "idCustomer")
private Collection<customer> customerCollection;
}
@Entity
public class product implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Basic(optional = false)
@NotNull
@Column(name = "ID_PRODUCT", nullable = false)
private Integer idProduct;
private Date date;
@ManyToMany(mappedBy = "productCollection")
private Collection<Acces> orderCollection;
}