我有这堂课:
@Entity
@Table(name = "TOPUP_MESSAGE")
public class ReportFee {
//... ID & Other Properties
@ManyToOne
@JoinColumn(name="CONTRACT_ID")
private ContractDetail contractDetail;
//GETTERS AND SETTERS
}
和ContractDetail类是这样的:
@Entity
@Table(name = "CONTRACT_DETAIL")
public class ContractDetail {
//... ID & Other Properties
@ManyToOne
@JoinColumn(name = "CONTRACT_ID")
private Contract contract;
//GETTERS AND SETTERS
}
我的合同类是这样的:
@Entity
@Table(name = "CONTRACT")
public class Contract implements {
//... ID & Other Properties
@ManyToOne
@JoinColumn(name = "OPERATOR_ID")
private Operator operator;
//GETTERS AND SETTERS
}
我定义了这样的别名,但这是错误的:
Session session = (Session)this.em.getDelegate();
Criteria crit = session.createCriteria(getEntityClass());
crit = crit.createAlias("contractDetail", "cd", JoinType.LEFT_OUTER_JOIN);
crit = crit.createAlias("contract", "c", JoinType.LEFT_OUTER_JOIN);
crit = crit.createAlias("operator", "op", JoinType.LEFT_OUTER_JOIN);
Criterion c= Restrictions.eq("cd.cd.op", operator);
crit.add(c);
List result = crit.list();
但不幸的是我收到了这个错误:
org.hibernate.QueryException:无法解析属性:契约:x.be.ReportFee 在org.hibernate.persister.entity.AbstractPropertyMapping.propertyException(AbstractPropertyMapping.java:83) 在org.hibernate.persister.entity.AbstractPropertyMapping.toType(AbstractPropertyMapping.java:77) at org.hibernate.persister.entity.AbstractEntityPersister.toType(AbstractEntityPersister.java:1809) at org.hibernate.loader.criteria.EntityCriteriaInfoProvider.getType(EntityCriteriaInfoProvider.java:57) 在org.hibernate.loader.criteria.CriteriaQueryTranslator.getPathInfo(CriteriaQueryTranslator.java:251) 在org.hibernate.loader.criteria.CriteriaQueryTranslator.createCriteriaEntityNameMap(CriteriaQueryTranslator.java:230) 在org.hibernate.loader.criteria.CriteriaQueryTranslator。(CriteriaQueryTranslator.java:112) 在org.hibernate.loader.criteria.CriteriaLoader。(CriteriaLoader.java:84) 在org.hibernate.internal.SessionImpl.list(SessionImpl.java:1464) 在org.hibernate.internal.CriteriaImpl.list(CriteriaImpl.java:374) at x.findByCriteria(GenericJpaDao.java:195) at x.ReportFeeSb.getAllValidReportFees(ReportFeeSb.java:54) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 在java.lang.reflect.Method.invoke(Method.java:597) 在com.bea.core.repackaged.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:310) 在com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:182) 在com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149) at com.bea.core.repackaged.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:131) 在com.bea.core.repackaged.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:119) 在com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171) 在com.bea.core.repackaged.springframework.jee.spi.MethodInvocationVisitorImpl.visit(MethodInvocationVisitorImpl.java:37) 在weblogic.ejb.container.injection.EnvironmentInterceptorCallbackImpl.callback(EnvironmentInterceptorCallbackImpl.java:54) 在com.bea.core.repackaged.springframework.jee.spi.EnvironmentInterceptor.invoke(EnvironmentInterceptor.java:50) 在com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171) 在com.bea.core.repackaged.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:89) 在com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171) at com.bea.core.repackaged.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:131) 在com.bea.core.repackaged.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:119) 在com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171) 在com.bea.core.repackaged.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204) 在$ Proxy393.getAllValidReportFees(未知来源) at x.ReportFeeSi_kf36yv_ReportFeeSiImpl .__ WL_invoke(Unknown Source) 在weblogic.ejb.container.internal.SessionRemoteMethodInvoker.invoke(SessionRemoteMethodInvoker.java:40) at x.ReportFeeSi_kf36yv_ReportFeeSiImpl.getAllValidReportFees(Unknown Source) at x.ReportFeeSi_kf36yv_ReportFeeSiImpl_WLSkel.invoke(Unknown Source) 在weblogic.rmi.internal.ServerRequest.sendReceive(ServerRequest.java:174) 在weblogic.rmi.cluster.ClusterableRemoteRef.invoke(ClusterableRemoteRef.java:345) 在weblogic.rmi.cluster.ClusterableRemoteRef.invoke(ClusterableRemoteRef.java:259) at x.ReportFeeSi_kf36yv_ReportFeeSiImpl_1034_WLStub.getAllValidReportFees(Unknown Source) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 在java.lang.reflect.Method.invoke(Method.java:597) 在weblogic.ejb.container.internal.RemoteBusinessIntfProxy.invoke(RemoteBusinessIntfProxy.java:85) 在$ Proxy392.getAllValidReportFees(未知来源) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 在java.lang.reflect.Method.invoke(Method.java:597) 在x.invoke(SlsbDynamicDelegate.java:66) 在$ Proxy391.getAllValidReportFees(未知来源) at xxx.ReportFeeBean.performAction(ReportFeeBean.java:61) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 在java.lang.reflect.Method.invoke(Method.java:597) at com.sun.el.parser.AstValue.invoke(Unknown Source) at com.sun.el.MethodExpressionImpl.invoke(Unknown Source) at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105) at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:88) at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102) 在javax.faces.component.UICommand.broadcast(UICommand.java:315) 在javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:794) 在javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1259) at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81) 在com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101) 在com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118) 在javax.faces.webapp.FacesServlet.service(FacesServlet.java:593) 在weblogic.servlet.internal.StubSecurityHelper $ ServletServiceAction.run(StubSecurityHelper.java:227) 在weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125) 在weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:300) 在weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:26) 在weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56) 在weblogic.servlet.internal.RequestEventsFilter.doFilter(RequestEventsFilter.java:27) 在weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56) at weblogic.servlet.internal.WebAppServletContext $ ServletInvocationAction.wrapRun(WebAppServletContext.java:3715) at weblogic.servlet.internal.WebAppServletContext $ ServletInvocationAction.run(WebAppServletContext.java:3681) 在weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321) 在weblogic.security.service.SecurityManager.runAs(SecurityManager.java:120) 在weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2277) 在weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2183) 在weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1454) 在weblogic.work.ExecuteThread.execute(ExecuteThread.java:207) 在weblogic.work.ExecuteThread.run(ExecuteThread.java:176)
这里是如何创建类的:
----ReportFee (private ContractDetail contractDetail)
|
------ ContractDetail (private Contract contract)
|
-------- Contract (private Contract contract)
我将如何解决这个问题,提前完成????
答案 0 :(得分:3)
我在定义嵌套层次结构时解决了这个问题:
Session session = (Session)this.em.getDelegate();
Criteria crit = session.createCriteria(getEntityClass());
crit = crit.createAlias("contractDetail", "cd", JoinType.LEFT_OUTER_JOIN);
crit = crit.createAlias("cd.contract", "c", JoinType.LEFT_OUTER_JOIN);
Criterion criterion= Restrictions.eq("c.operator", operator);
crit.add(c);
List result = crit.list();