出现以下异常:
由以下原因导致:org.hibernate.QueryException:无法解析属性:com.hcentive.user.ContactInfo的primaryAddress 在org.hibernate.persister.entity.AbstractPropertyMapping.propertyException(AbstractPropertyMapping.java:62)〜[hibernate-core-5.1.0.Final.jar:5.1.0.Final] 在org.hibernate.persister.entity.AbstractPropertyMapping.toType(AbstractPropertyMapping.java:56)〜[hibernate-core-5.1.0.Final.jar:5.1.0.Final] 在org.hibernate.persister.entity.AbstractEntityPersister.getSubclassPropertyTableNumber(AbstractEntityPersister.java:1805)〜[hibernate-core-5.1.0.Final.jar:5.1.0.Final] 在org.hibernate.persister.entity.BasicEntityPropertyMapping.toColumns(BasicEntityPropertyMapping.java:46)〜[hibernate-core-5.1.0.Final.jar:5.1.0.Final] 在org.hibernate.persister.entity.AbstractEntityPersister.toColumns(AbstractEntityPersister.java:1780)〜[hibernate-core-5.1.0.Final.jar:5.1.0.Final] 在org.hibernate.loader.criteria.CriteriaQueryTranslator.getColumns(CriteriaQueryTranslator.java:510)〜[hibernate-core-5.1.0.Final.jar:5.1.0.Final] 在org.hibernate.loader.criteria.CriteriaQueryTranslator.getColumnsUsingProjection(CriteriaQueryTranslator.java:469)〜[hibernate-core-5.1.0.Final.jar:5.1.0.Final] 在org.hibernate.criterion.Order.toSqlString(Order.java:109)〜[hibernate-core-5.1.0.Final.jar:5.1.0.Final] 在org.hibernate.loader.criteria.CriteriaQueryTranslator.getOrderBy(CriteriaQueryTranslator.java:414)〜[hibernate-core-5.1.0.Final.jar:5.1.0.Final] 在org.hibernate.loader.criteria.CriteriaJoinWalker。(CriteriaJoinWalker.java:106)〜[hibernate-core-5.1.0.Final.jar:5.1.0.Final] 在org.hibernate.loader.criteria.CriteriaJoinWalker。(CriteriaJoinWalker.java:75)〜[hibernate-core-5.1.0.Final.jar:5.1.0.Final] 在org.hibernate.loader.criteria.CriteriaLoader。(CriteriaLoader.java:80)〜[hibernate-core-5.1.0.Final.jar:5.1.0.Final] 在org.hibernate.internal.SessionImpl.list(SessionImpl.java:1773)〜[hibernate-core-5.1.0.Final.jar:5.1.0.Final] 在org.hibernate.internal.CriteriaImpl.list(CriteriaImpl.java:363)
在对数据表中的地址列进行排序时定义为:
{
"mData": function (customer) {
var address = customer.userProfile.contactInfo.primaryAddress;
return address ? address.displayString : "";
},
"aTargets": [4],
"sName": "userProfile.contactInfo.primaryAddress",
"sClass": "wrapWord100"
},
primaryAddress在ContactInfo.java实体中以吸气剂的形式出现
public Address getPrimaryAddress() {
for (Address add : addresses) {
if (null != add && AddressTypeEnum.Primary.toString().equals(add.getType())) {
return add;
}
}
return null;
}
private Set<Address> addresses = new HashSet<Address>();
该错误可能是因为'primaryAddress'在'ContactInfo'中不作为一列出现。 如何解决这个问题。
@Entity
@Table(name = "CONTACT_INFO")
public class ContactInfo extends Persistent {
private Set<Address> addresses = new HashSet<Address>();
@Valid
public Address getPrimaryAddress() {
for (Address add : addresses) {
if (null != add && AddressTypeEnum.Primary.toString().equals(add.getType())) {
return add;
}
}
return null;
}
}
答案 0 :(得分:0)
您需要将查询更改为此。同样,这将返回地址列表,而不是单个地址。
"mData": function (customer) {
var address = customer.userProfile.contactInfo.addresses;
return address ? address.displayString : "";
},
"aTargets": [4],
"sName": "userProfile.contactInfo.addresses",
"sClass": "wrapWord100"
},