持久化数据时的未知实体

时间:2014-07-25 13:02:11

标签: hibernate sql-server-2012 tapestry

我是Tapestry5的新手。我想将地址对象持久保存到SQ L Server 2012,同时坚持我得到以下异常。我瞪大了它的大多数帖子都说使用正确的实体注释。我只使用正确的注释。 这是我的地址实体

 package com.asd.exam.entities;

 import javax.persistence.Column;
 import javax.persistence.Entity;
 import javax.persistence.GeneratedValue;
 import javax.persistence.GenerationType;
 import javax.persistence.Id;
 import javax.persistence.Table;

 import org.apache.tapestry5.beaneditor.NonVisual;
 import org.apache.tapestry5.beaneditor.Validate;

 import com.asd.exam.data.Honorific;

 @Entity
 @Table(name="TBLADDRESS")
 public class Address {
 @Id
  @GeneratedValue(strategy = GenerationType.IDENTITY)
  @NonVisual
  @Column(name="SNO")
  public Long sno;

  @Validate("required")
  @Column(name="HONORIFIC")
  public Honorific honorific;

    @Validate("required")
      @Column(name="FIRSTNAME")
  public String firstname;

    @Validate("required")
      @Column(name="LASTNAME")
  public String lastName;

    @Validate("required")
      @Column(name="STREET1")
  public String street1;

    @Validate("required")
      @Column(name="STREET2")
  public String street2;

    @Validate("required")
      @Column(name="CITY")
  public String city;

    @Validate("required")
      @Column(name="STATE")
  public String state;

    @Validate("required,regexp")
      @Column(name="ZIPCODE")
  public Integer zipcode;

    @Validate("required")
      @Column(name="EMAIL")
  public String email;

    @Validate("required")
      @Column(name="PHONENUMBER")
  public String phonenumber;

}

和CreateAddress.java

 package com.asd.exam.pages;

 import org.apache.tapestry5.annotations.InjectPage;
 import org.apache.tapestry5.annotations.Property;
 import org.apache.tapestry5.hibernate.annotations.CommitAfter;
 import org.apache.tapestry5.ioc.annotations.Inject;
 import org.hibernate.Session;

 import com.asd.exam.entities.Address;

 public class CreateAddress {

@Property
private Address address;

@InjectPage
private Index index;

@Inject
private Session session;

@CommitAfter
Object onSuccess()
{
   session.persist(address);
    return index;
}

}

我的完整堆栈跟踪是

[INFO] hbm2ddl.SchemaUpdate schema update complete
[INFO] HibernateCoreModule.HibernateSessionSource Hibernate startup: 296 ms to configure, 734 ms overall.
[INFO] HibernateCoreModule.HibernateSessionSource Configured Hibernate entities: (none)
[ERROR] ioc.Registry Unknown entity: com.asd.exam.entities.Address
[ERROR] ioc.Registry Operations trace:
[ERROR] ioc.Registry [ 1] Triggering event 'action' on CreateAddress:beaneditform.form
[ERROR] ioc.Registry [ 2] Triggering event 'success' on CreateAddress:beaneditform.form
[ERROR] TapestryModule.RequestExceptionHandler Processing of request failed with uncaught exception: Unknown entity: com.asd.exam.entities.Address
org.apache.tapestry5.runtime.ComponentEventException: Unknown entity: com.asd.exam.entities.Address [at classpath:org/apache/tapestry5/corelib/components/BeanEditForm.tml, line 2]
    at org.apache.tapestry5.internal.structure.ComponentPageElementImpl.processEventTriggering(ComponentPageElementImpl.java:1141)
    at org.apache.tapestry5.internal.structure.ComponentPageElementImpl.access$3100(ComponentPageElementImpl.java:61)
    at org.apache.tapestry5.internal.structure.ComponentPageElementImpl$5.invoke(ComponentPageElementImpl.java:1062)
    at org.apache.tapestry5.internal.structure.ComponentPageElementImpl$5.invoke(ComponentPageElementImpl.java:1059)
    at org.apache.tapestry5.ioc.internal.OperationTrackerImpl.invoke(OperationTrackerImpl.java:74)
    at org.apache.tapestry5.ioc.internal.PerThreadOperationTracker.invoke(PerThreadOperationTracker.java:87)
    at org.apache.tapestry5.ioc.internal.RegistryImpl.invoke(RegistryImpl.java:1124)
    at org.apache.tapestry5.internal.structure.ComponentPageElementResourcesImpl.invoke(ComponentPageElementResourcesImpl.java:146)
    at org.apache.tapestry5.internal.structure.ComponentPageElementImpl.triggerContextEvent(ComponentPageElementImpl.java:1058)
    at org.apache.tapestry5.internal.services.ComponentEventRequestHandlerImpl.handle(ComponentEventRequestHandlerImpl.java:81)
    at org.apache.tapestry5.internal.services.ImmediateActionRenderResponseFilter.handle(ImmediateActionRenderResponseFilter.java:42)
    at $ComponentEventRequestHandler_1c80b398c6cd.handle(Unknown Source)
    at org.apache.tapestry5.internal.services.AjaxFilter.handle(AjaxFilter.java:42)
    at $ComponentEventRequestHandler_1c80b398c6cd.handle(Unknown Source)
    at org.apache.tapestry5.services.TapestryModule$41.handle(TapestryModule.java:2476)
    at $ComponentEventRequestHandler_1c80b398c6cd.handle(Unknown Source)
    at $ComponentEventRequestHandler_1c80b398c6c4.handle(Unknown Source)
    at org.apache.tapestry5.internal.services.ComponentRequestHandlerTerminator.handleComponentEvent(ComponentRequestHandlerTerminator.java:43)
    at org.apache.tapestry5.services.InitializeActivePageName.handleComponentEvent(InitializeActivePageName.java:39)
    at $ComponentRequestHandler_1c80b398c6c6.handleComponentEvent(Unknown Source)
    at $ComponentRequestHandler_1c80b398c697.handleComponentEvent(Unknown Source)
    at org.apache.tapestry5.internal.services.ComponentEventDispatcher.dispatch(ComponentEventDispatcher.java:46)
    at $Dispatcher_1c80b398c69a.dispatch(Unknown Source)
    at $Dispatcher_1c80b398c693.dispatch(Unknown Source)
    at org.apache.tapestry5.services.TapestryModule$RequestHandlerTerminator.service(TapestryModule.java:302)
    at org.apache.tapestry5.internal.services.RequestErrorFilter.service(RequestErrorFilter.java:26)
    at $RequestHandler_1c80b398c694.service(Unknown Source)
    at org.apache.tapestry5.services.TapestryModule$3.service(TapestryModule.java:902)
    at $RequestHandler_1c80b398c694.service(Unknown Source)
    at org.apache.tapestry5.services.TapestryModule$2.service(TapestryModule.java:892)
    at $RequestHandler_1c80b398c694.service(Unknown Source)
    at org.apache.tapestry5.internal.services.StaticFilesFilter.service(StaticFilesFilter.java:90)
    at $RequestHandler_1c80b398c694.service(Unknown Source)
    at com.asd.exam.services.AppModule$1.service(AppModule.java:89)
    at $RequestFilter_1c80b398c68f.service(Unknown Source)
    at $RequestHandler_1c80b398c694.service(Unknown Source)
    at $RequestHandler_1c80b398c688.service(Unknown Source)
    at org.apache.tapestry5.services.TapestryModule$HttpServletRequestHandlerTerminator.service(TapestryModule.java:253)
    at org.apache.tapestry5.internal.gzip.GZipFilter.service(GZipFilter.java:53)
    at $HttpServletRequestHandler_1c80b398c68a.service(Unknown Source)
    at org.apache.tapestry5.internal.services.IgnoredPathsFilter.service(IgnoredPathsFilter.java:62)
    at $HttpServletRequestFilter_1c80b398c686.service(Unknown Source)
    at $HttpServletRequestHandler_1c80b398c68a.service(Unknown Source)
    at org.apache.tapestry5.services.TapestryModule$1.service(TapestryModule.java:852)
    at $HttpServletRequestHandler_1c80b398c68a.service(Unknown Source)
    at $HttpServletRequestHandler_1c80b398c685.service(Unknown Source)
    at org.apache.tapestry5.TapestryFilter.doFilter(TapestryFilter.java:171)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1212)
    at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:399)
    at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
    at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
    at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:766)
    at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:450)
    at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
    at org.mortbay.jetty.Server.handle(Server.java:326)
    at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
    at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:945)
    at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:756)
    at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:218)
    at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
    at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:410)
    at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)
**Caused by: org.apache.tapestry5.ioc.internal.OperationException: Unknown entity: com.asd.exam.entities.Address** [at classpath:org/apache/tapestry5/corelib/components/BeanEditForm.tml, line 2]
    at org.apache.tapestry5.ioc.internal.OperationTrackerImpl.logAndRethrow(OperationTrackerImpl.java:121)
    at org.apache.tapestry5.ioc.internal.OperationTrackerImpl.invoke(OperationTrackerImpl.java:88)
    at org.apache.tapestry5.ioc.internal.PerThreadOperationTracker.invoke(PerThreadOperationTracker.java:87)
    at org.apache.tapestry5.ioc.internal.RegistryImpl.invoke(RegistryImpl.java:1124)
    at org.apache.tapestry5.internal.structure.ComponentPageElementResourcesImpl.invoke(ComponentPageElementResourcesImpl.java:146)
    at org.apache.tapestry5.internal.structure.ComponentPageElementImpl.triggerContextEvent(ComponentPageElementImpl.java:1058)
    at org.apache.tapestry5.internal.structure.InternalComponentResourcesImpl.triggerContextEvent(InternalComponentResourcesImpl.java:302)
    at org.apache.tapestry5.corelib.components.Form.advised$onAction_1c80b398c717(Form.java:562)
    at org.apache.tapestry5.corelib.components.Form$Invocation_onAction_1c80b398c716.proceedToAdvisedMethod(Unknown Source)
    at org.apache.tapestry5.internal.plastic.AbstractMethodInvocation.proceed(AbstractMethodInvocation.java:84)
    at org.apache.tapestry5.ioc.internal.services.LoggingAdvice.advise(LoggingAdvice.java:37)
    at org.apache.tapestry5.internal.plastic.AbstractMethodInvocation.proceed(AbstractMethodInvocation.java:86)
    at org.apache.tapestry5.corelib.components.Form.onAction(Form.java)
    at org.apache.tapestry5.corelib.components.Form.dispatchComponentEvent(Form.java)
    at org.apache.tapestry5.internal.structure.ComponentPageElementImpl.dispatchEvent(ComponentPageElementImpl.java:932)
    at org.apache.tapestry5.internal.structure.ComponentPageElementImpl.processEventTriggering(ComponentPageElementImpl.java:1117)
    ... 61 more
**Caused by: org.apache.tapestry5.runtime.ComponentEventException: Unknown entity: com.asd.exam.entities.Address** [at classpath:org/apache/tapestry5/corelib/components/BeanEditForm.tml, line 2]
    at org.apache.tapestry5.internal.structure.ComponentPageElementImpl.processEventTriggering(ComponentPageElementImpl.java:1141)
    at org.apache.tapestry5.internal.structure.ComponentPageElementImpl.access$3100(ComponentPageElementImpl.java:61)
    at org.apache.tapestry5.internal.structure.ComponentPageElementImpl$5.invoke(ComponentPageElementImpl.java:1062)
    at org.apache.tapestry5.internal.structure.ComponentPageElementImpl$5.invoke(ComponentPageElementImpl.java:1059)
    at org.apache.tapestry5.ioc.internal.OperationTrackerImpl.invoke(OperationTrackerImpl.java:74)
    ... 75 more
**Caused by: org.hibernate.MappingException: Unknown entity: com.asd.exam.entities.Address**
    at org.hibernate.impl.SessionFactoryImpl.getEntityPersister(SessionFactoryImpl.java:691)
    at org.hibernate.impl.SessionImpl.getEntityPersister(SessionImpl.java:1494)
    at org.hibernate.engine.ForeignKeys.isTransient(ForeignKeys.java:202)
    at org.hibernate.event.def.AbstractSaveEventListener.getEntityState(AbstractSaveEventListener.java:531)
    at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:102)
    at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:61)
    at org.hibernate.impl.SessionImpl.firePersist(SessionImpl.java:808)
    at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:782)
    at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:786)
    at $Session_1c80b398c78a.persist(Unknown Source)
    at $Session_1c80b398c6c1.persist(Unknown Source)
    at com.asd.exam.pages.CreateAddress.onSuccess(CreateAddress.java:25)
    at com.asd.exam.pages.CreateAddress.dispatchComponentEvent(CreateAddress.java)
    at org.apache.tapestry5.internal.structure.ComponentPageElementImpl.dispatchEvent(ComponentPageElementImpl.java:932)
    at org.apache.tapestry5.internal.structure.ComponentPageElementImpl.processEventTriggering(ComponentPageElementImpl.java:1117)
    ... 79 more
[INFO] AppModule.TimingFilter Request time: 3598 ms

必须非常感谢帮助。

2 个答案:

答案 0 :(得分:0)

您的pom.xml中似乎缺少实体依赖项,请确保您需要所有依赖项。

类似的东西:

<dependency>
  <groupId>com.asd.exam.entities</groupId>
  <artifactId>package-path-to-adress</artifactId>
  <version>X.X.X</version>
</dependency>

答案 1 :(得分:0)

尝试将以下行添加到hibernate.cfg.xml

<mapping package="com.asd.exam.entities" />