I have 2 tables Customer and Contact
Customer Entity: @OneToMany(cascade = CascadeType.REFRESH, mappedBy="customer", fetch = FetchType.EAGER) @MapKey(name="fieldName") private Map<String, Contact> contacts;
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;
The JPQL is, select c from Customer c where c.contacts['home'].fieldValue='1234' But I got the error message, incorrect syntax near the keyword 'null' I display the normal query as below (it's not copied, just write here roughly)
select ... from Customer as customer1, contact as contact1 where customer1.id=contact1.customer_id and contact1.null = 'home' and contact1.field_value='1234' I find the mapkey is not translated to column name contact1.null = 'home'. It should be contact1.field_name = 'home'
Did I miss something here? The database is MS SQL.
Since some problem for this MapKey, I am thinking to change the Map to Set. Part of Customer Entity: @OneToMany(cascade = CascadeType.REFRESH, mappedBy="customer", fetch = FetchType.EAGER)
private Set<Contact> contacts;
If use Set instead of Map, what's this JPQL should be? select c from Customer c where c.contacts['home'].fieldValue='1234'
|