我得到了一个类未映射的异常,但是我想我确实映射了它!我有 2 个类 ClientAppts 和 Appointments 有一对多的关系。我想得到所有的客户和他们的约会日期。是什么原因造成的?欢迎所有建议。
这是课程:
@Entity(name="ClientAppts")
@Table(name="person")
public class ClientAppts {
private Integer person_id;
private String fName;
private String lName;
private Date appt;
private String phone;
private String cell;
private String address1;
private String address2;
private String city;
private String state;
private String zip;
private String doctor;
private String notes;
@ElementCollection
@CollectionTable(name="Appointment", joinColumns= @JoinColumn(name="person_id"))
@Column(name="appt")
Collection<Date> appointments;
// various getters and setters follow.
为了清楚起见,这里是上面提到的 Appointment 类:
@Entity(name="Appointment")
@Table(name="appointment")
public class Appointment {
private int id;
private Date appt;
private Date apptfinish;
private String title;
private String location;
private BigDecimal fee;
private BigDecimal amtPaid;
private Boolean serviceRendered;
private int person_id;
private String description;
这是引发异常的代码:
List<ClientAppts> list = getSessionFactory().getCurrentSession().createQuery(" from ClientAppts client order by client.lName ").list();
最后,堆栈跟踪:
org.hibernate.hql.internal.ast.QuerySyntaxException:ClientAppts 未映射 [from ClientAppts client order by client.lName] at org.hibernate.hql.internal.ast.util.SessionFactoryHelper.requireClassPersister(SessionFactoryHelper.java:180) at org.hibernate.hql.internal.ast.tree.FromElementFactory.addFromElement(FromElementFactory.java:110) 在 org.hibernate.hql.internal.ast.tree.FromClause.addFromElement(FromClause.java:93) 在 org.hibernate。 hql.internal.ast.HqlSqlWalker.createFromElement(HqlSqlWalker.java:326) 在 org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.fromElement(HqlSqlBaseWalker.java:3252) 在 org.hibernate.hql.internal.antlr.HqlSqlBaseWalker。 fromElementList(HqlSqlBaseWalker.java:3141) at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.fromClause(HqlSqlBaseWalker.java:694) at org.hibernate.hql.internal。antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:550) at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:287) at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker. java:235) 在 org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:183) 在 org.hibernate 的 org.hibernate.hql.internal.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:248) .hql.internal.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:136) 在 org.hibernate.engine.query.spi.HQLQueryPlan.(HQLQueryPlan.java:101) 在 org.hibernate.engine.query.spi.HQLQueryPlan。 (HQLQueryPlan.java:80) 位于 org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:119) 位于 org.hibernate.internal.AbstractSessionImpl。getHQLQueryPlan(AbstractSessionImpl.java:215) 在 org.hibernate.internal.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:193) 在 org.hibernate.internal.SessionImpl.createQuery(SessionImpl.java:1649) 在 com.dave.user.dao .UserDAO.getClientAppts(UserDAO.java:130) 在 com.dave.user.service.UserService.getClientAppts(UserService.java:126) 在 sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 在 sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:39) 在 sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 在 java.lang.reflect.Method.invoke(Method.java:597) 在 org.springframework.aop.support.AopUtils。在 org.springframework.aop.framework.ReflectiveMethodInvocation 处调用JoinpointUsingReflection(AopUtils.java:318)。invokeJoinpoint(ReflectiveMethodInvocation.java:183) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150) at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110) at org.springframework .aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202) at $Proxy251.getClientAppts(Unknown Source) at com.dave.managed。 bean.AppointmentsMB.loadAppointments(AppointmentsMB.java:45) 在 com.dave.managed.bean.AppointmentsMB.init(AppointmentsMB.java:40) 在 sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 在 sun.reflect.NativeMethodAccessorImpl。在太阳调用(NativeMethodAccessorImpl.java:39)。reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.glassfish.faces.integration.GlassFishInjectionProvider$2.run(GlassFishInjectionProvider.java:382) at java.security.AccessController.doPrivileged(Native Method) at org.glassfish.faces.integration.GlassFishInjectionProvider.invokeLifecycleMethod(GlassFishInjectionProvider.java:376) at org.glassfish.faces.integration.GlassFishInjectionProvider.invokePostConstruct(GlassFishInjectionProvider.java:306) at org.glassfish.faces.integration.GlassFishInjectionProvider.invokePostConstruct(GlassFishInjectionProvider.java:229) at com.sun.faces.mgbean.BeanBuilder.invokePostConstruct(BeanBuilder.java:223) at com.sun.faces.mgbean.BeanBuilder.build( BeanBuilder.java:105) 在 com.sun.faces。mgbean.BeanManager.createAndPush(BeanManager.java:409) at com.sun.faces.mgbean.BeanManager.create(BeanManager.java:269) at com.sun.faces.el.ManagedBeanELResolver.resolveBean(ManagedBeanELResolver.java:244)在 com.sun.faces.el.ManagedBeanELResolver.getValue(ManagedBeanELResolver.java:116) 在 com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:176) 在 com.sun.faces.el.DemuxCompositeELResolver.getValue (DemuxCompositeELResolver.java:203) 在 com.sun.el.parser.AstValue.getValue(AstValue.java:179) 在 com.sun.sun.el.parser.AstIdentifier.getValue(AstIdentifier.java:103)。 el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:224) 在 com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:109) 在 javax.faces.component.ComponentStateHelper。eval(ComponentStateHelper.java:194) at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:182) at javax.faces.component.UIOutput.getValue(UIOutput.java:169) at org.primefaces.component.calendar .CalendarUtils.getValueAsString(CalendarUtils.java:35) at org.primefaces.component.calendar.CalendarRenderer.encodeEnd(CalendarRenderer.java:58) at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:875) at com。 sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeRecursive(HtmlBasicRenderer.java:312) at com.sun.faces.renderkit.html_basic.GroupRenderer.encodeChildren(GroupRenderer.java:105) at javax.faces.component.UIComponentBase.encodeChildren( UIComponentBase.java:845) 在 com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeRecursive(HtmlBasicRenderer.java:304) 在 com.sun.faces.renderkit.html_basic.GridRenderer.renderRow(GridRenderer.java:185) at com.sun.faces.renderkit.html_basic.GridRenderer.encodeChildren(GridRenderer.java:129) at javax.faces.component.UIComponentBase.encodeChildren( UIComponentBase.java:845) 在 javax.faces.component.UIComponent.encodeAll(UIComponent.java:1757) 在 javax.faces.render.Renderer.encodeChildren(Renderer.java:168) 在 javax.faces.component.UIComponentBase.encodeChildren (UIComponentBase.java:845) 在 javax.faces.component.UIComponent.encodeAll(UIComponent.java:1757) 在 javax.faces.component.UIComponent.encodeAll(UIComponent.java:1760) 在 javax.faces.component.UIComponent。 com.sun.faces.application.view.FaceletViewHandlingStrategy 的 javax.faces.component.UIComponent.encodeAll(UIComponent.java:1760) 的 encodeAll(UIComponent.java:1760)。renderView(FaceletViewHandlingStrategy.java:402) at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:131) at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:288) at org.apache .myfaces.tomahawk.application.ResourceViewHandlerWrapper.renderView(ResourceViewHandlerWrapper.java:93) 在 com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:121) 在 com.sun.faces.lifecycle.Phase.doPhase(Phase .java:101) 在 com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139) 在 javax.faces.webapp.FacesServlet.service(FacesServlet.java:594) 在 org.apache.catalina.core。 StandardWrapper.service(StandardWrapper.java:1542) 在 org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:281) 在 org.apache.catalina.core。StandardContextValve.invoke(StandardContextValve.java:175) at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595) at org .apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:161) at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:331) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter .java:231) 在 com.sun.enterprise.v3.services.impl.ContainerMapper$AdapterCallable.call(ContainerMapper.java:317) 在 com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java :195) 在 com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:849) 在 com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:746) 在 com.sun.grizzly。http.ProcessorTask.process(ProcessorTask.java:1045) 在 com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:228) 在 com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137) 在 com .sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104) 在 com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90) 在 com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79 ) 在 com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54) 在 com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59) 在 com.sun.grizzly.ContextTask.run(ContextTask.java: 71) 在 com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532) 在 com.sun.grizzly.util。AbstractThreadPool$Worker.run(AbstractThreadPool.java:513) 在 java.lang.Thread.run(Thread.java:662)