I asked the question in my last post but not sure why no reply. So I post it again as an standalone question.
I have 2 tables Customer and Contact. One customer can have multiple contacts. So the relationship is one to many.
Part of Customer Entity: @OneToMany(cascade = CascadeType.REFRESH, mappedBy="customer", fetch = FetchType.EAGER) private Set<Contact> contacts;
Part of Contact Entity: @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "customer_ID") private Customer customer;
@Column(name = "FIELD_NAME") @NotNull private String fieldName;
@Column(name = "FIELD_VALUE") @Length(max = 100, message = "Maximum length allowed for user defined field is 100") private String fieldValue;
Now I want to search out the customers based on the contact criterias. For example, the criteria is fieldName='home number' and fieldValue='1234'
How to write such JPQL? It could looks like, select c from Customer c where c.contacts.fieldName='home number' and c.contacts.fieldValue='1234'
|