我有两个 tables Customer and Contact. One customer can have multiple contacts.
是一对多的关系。两个entity的部分代码如下
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;现在要写一条查询jpql语句,根据contact表的fieldName和fieldValue查询
For example, the criteria is fieldName='home number' and fieldValue='1234'怎么写这样的jpql语句?
我试过这样写不对
select c from Customer c where c.contacts.fieldName='home number' and c.contacts.fieldValue='1234'