我有一个Embeddable类,它嵌入在实体中。
@Embeddable
public class RawObservation{
@NotNull
@Column(name="RAW_CODE")
private String rawCode;
// getters,setters
}
@Entity
public class TankObservation{
@Embedded
private RawObservation rawObservation;
}
当我尝试使用“ rawCode”参数进行GET查询时;
Hiberanate引发以下异常[1];
我该如何克服?
Caused by: org.hibernate.QueryException: could not resolve property: rawCode of: com.abc.TankObservation
at org.hibernate.persister.entity.AbstractPropertyMapping.propertyException(AbstractPropertyMapping.java:62)
at org.hibernate.persister.entity.AbstractPropertyMapping.toType(AbstractPropertyMapping.java:56)
at org.hibernate.persister.entity.AbstractEntityPersister.getSubclassPropertyTableNumber(AbstractEntityPersister.java:1770)
at org.hibernate.persister.entity.BasicEntityPropertyMapping.toColumns(BasicEntityPropertyMapping.java:46)
at org.hibernate.persister.entity.AbstractEntityPersister.toColumns(AbstractEntityPersister.java:1745)
at org.hibernate.loader.criteria.CriteriaQueryTranslator.getColumns(CriteriaQueryTranslator.java:510)
at org.hibernate.loader.criteria.CriteriaQueryTranslator.findColumns(CriteriaQueryTranslator.java:525)
at org.hibernate.criterion.SimpleExpression.toSqlString(SimpleExpression.java:66)
at org.hibernate.loader.criteria.CriteriaQueryTranslator.getWhereCondition(CriteriaQueryTranslator.java:400)
at org.hibernate.loader.criteria.CriteriaJoinWalker.<init>(CriteriaJoinWalker.java:106)
at org.hibernate.loader.criteria.CriteriaJoinWalker.<init>(CriteriaJoinWalker.java:75)
at org.hibernate.loader.criteria.CriteriaLoader.<init>(CriteriaLoader.java:80)
at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1760)
at org.hibernate.internal.CriteriaImpl.list(CriteriaImpl.java:363)
at com.cdi.crud.infra.Crud.list(Crud.java:437)
at com.cdi.crud.infra.CrudService.paginate(CrudService.java:128)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.jboss.as.ee.component.ManagedReferenceMethodInterceptor.processInvocation(ManagedReferenceMethodInterceptor.java:52)
编辑:
public Criteria configPagination(Filter<TankObservation> filter) {
if (filter.getEntity() != null) {
if(filter.getEntity().getRawObservation().getRawCode() != null){
crud().eq("rawCode", filter.getEntity().getRawObservation().getRawCode());
}
if(filter.getEntity().getRawObservation().getProductCode() != null){
crud().eq("productCode", filter.getEntity().getRawObservation().getProductCode());
}
}
return crud().getCriteria();
}
最佳答案
rawCode
中没有属性TankObservation
。请用rawObservation.rawCode
引用rawCode
中的TankObservation
。