问题描述
两个表CustomerandContact一对多的关系.Thatmeansonecustomerhasmultiplecontacts.部分entity的代码如下,我想用Map来表示这个一对多关系CustomerEntity:@OneToMany(cascade=CascadeType.REFRESH,mappedBy="customer",fetch=FetchType.EAGER)@MapKey(name="fieldName")privateMap<String,Contact>contacts;ContactEntity:@ManyToOne(fetch=FetchType.LAZY)@JoinColumn(name="customer_ID")privateCustomercustomer;@Column(name="FIELD_NAME")@NotNullprivateStringfieldName;@Column(name="FIELD_VALUE")@Length(max=100,message="Maximumlengthallowedforuserdefinedfieldis100")privateStringfieldValue;TheJPQL语句如下selectcfromCustomercwherec.contacts['home'].fieldValue='1234'但是在执行这个jpql语句时碰到这个出错信息,Hibernate:select....fromCustomercustomer0_,Contactcontact1_wherecustomer0_.id=contact1_.CUSTOMER_IDandcontact1_.null='home'andcontact1_.FIELD_VALUE='1234'ERROR[main][]org.hibernate.util.JDBCExceptionReporter-Incorrectsyntaxnearthekeyword'null'.可以注意到mapkey没有被成功转成表列名contact1_.null='home'.应该是contact1_.field_name='home'就对了谁有这方面的经验,问题出在哪里呢?数据库是MSSQL.