本文介绍了Hibernate无法解析嵌入类的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
@Embeddable
public class RawObservation {
@NotNull
@Column(name =RAW_CODE)
private String rawCode;
// getters,setters
}
@Entity
公共类TankObservation {
@Embedded
私有RawObservation rawObservation;
}
当我尝试使用rawCode参数进行GET查询时, p>
Hiberanate引发以下异常[1];
我该如何克服这一点?
原因:org.hibernate.QueryException:无法解析属性:rawCode of:com.abc.TankObservation
at org.hibernate.persister.entity .AbstractPropertyMapping.propertyException(AbstractPropertyMapping.java:62)
在org.hibernate.persister.entity.AbstractPropertyMapping.toType(AbstractPropertyMapping.java:56)
在org.hibernate.persister.entity.AbstractEntityPersister.getSubclassPropertyTableNumber在org.hibernate.persister.entity.BasicEntityPropertyMapping.toColumns(AbstractEntityPersister.java:1770)
(BasicEntityPropertyMapping.java:46)
在org.hibernate.persister.entity.AbstractEntityPersister.toColumns(AbstractEntityPersister.java :1745)
org.hibernate.loader.criteria.CriteriaQueryTranslator.getColumns( CriteriaQueryTranslator.java:510)
在org.hibernate.loader.criteria.CriteriaQueryTranslator.findColumns(CriteriaQueryTranslator.java:525)
在org.hibernate.criterion.SimpleExpression.toSqlString(SimpleExpression.java:66)在org.hibernate.loader.criteria.CriteriaQueryTranslator.getWhereCondition(CriteriaQueryTranslator.java:400)
。在org.hibernate.loader.criteria.CriteriaJoinWalker<初始化>(CriteriaJoinWalker.java:106)$ INIT> LT b $ b。在org.hibernate.loader.criteria.CriteriaJoinWalker&(CriteriaJoinWalker.java:75)
。在org.hibernate.loader.criteria.CriteriaLoader<初始化>(CriteriaLoader.java:80 )
在org.hibernate.internal.SessionImpl.list(SessionImpl.java:1760)
在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(原生M ethod)
在sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
在sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
在java.lang.reflect中.Method.invoke(Method.java:497)
at org.jboss.as.ee.component.ManagedReferenceMethodInterceptor.processInvocation(ManagedReferenceMethodInterceptor.java:52)
$ b 编辑:
public Criteria configPagination(过滤和LT; TankObservation>过滤器){
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
从 TankObservation $>中引用
rawCode
c $ c>。
I have an Embeddable class, which is embedded in an entity.
@Embeddable
public class RawObservation{
@NotNull
@Column(name="RAW_CODE")
private String rawCode;
//getters,setters }
@Entity
public class TankObservation{
@Embedded
private RawObservation rawObservation;
}
When I try to make a GET query with "rawCode" parameter;
Hiberanate throws following exception[1];
How can I overcome this?
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)
Edit :
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();
}
解决方案
There is not property rawCode
in the TankObservation
. Please, use rawObservation.rawCode
to refer rawCode
from TankObservation
.
这篇关于Hibernate无法解析嵌入类的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!