Hibernate无法识别@Id annottation

时间:2016-06-18 18:01:23

标签: hibernate jpa java-ee wildfly

我正在使用JSF 2.1 + JPA / Hibernate(随AS提供)+ Wildfly 9.2,但在项目部署期间,它没有启动并抛出与@Id注释相关的错误,已经给出了

这是我的 PostsEntity 类的片段:

@Entity
public class PostsEntity implements Serializable {
  private static final long serialVersionUID = 1L;
  @Id
  @GeneratedValue(strategy = GenerationType.AUTO)
  @Column(name = "post_id")
  private Integer post_id;

  public PostsEntity() {

  }

  public Integer getPostId() {
      return post_id;
  }

  public void setPostId(Integer id) {
      this.post_id = id;
  }
}

这是我的 persistence.xml

<?xml version="1.0" encoding="UTF-8"?>
<persistence
    xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_1.xsd"
    version="2.1">
    <persistence-unit name="conn">
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
        <jta-data-source>java:/belike_ds</jta-data-source>
        <properties>
            <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />
            <property name="hibernate.hbm2ddl.auto" value="create" />
        </properties>
    </persistence-unit>
</persistence>

这是完整的堆栈跟踪:

13:52:38,898 ERROR [org.jboss.msc.service.fail] (ServerService Thread Pool -- 83) MSC000001: Failed to start service jboss.persistenceunit."belike.war#conn": org.jboss.msc.service.StartException in service jboss.persistenceunit."belike.war#conn": javax.persistence.PersistenceException: [PersistenceUnit: conn] Unable to build Hibernate SessionFactory
    at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:172)
    at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:117)
    at org.wildfly.security.manager.WildFlySecurityManager.doChecked(WildFlySecurityManager.java:665)
    at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1.run(PersistenceUnitServiceImpl.java:182)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
    at org.jboss.threads.JBossThread.run(JBossThread.java:320)
Caused by: javax.persistence.PersistenceException: [PersistenceUnit: conn] Unable to build Hibernate SessionFactory
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.persistenceException(EntityManagerFactoryBuilderImpl.java:1249)
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.access$600(EntityManagerFactoryBuilderImpl.java:120)
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:860)
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:850)
    at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.withTccl(ClassLoaderServiceImpl.java:425)
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:849)
    at org.jboss.as.jpa.hibernate4.TwoPhaseBootstrapImpl.build(TwoPhaseBootstrapImpl.java:44)
    at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:154)
    ... 7 more
Caused by: org.hibernate.AnnotationException: No identifier specified for entity: com.rafaelsilverioamaral.belike.entities.PostsEntity
    at org.hibernate.cfg.InheritanceState.determineDefaultAccessType(InheritanceState.java:277)
    at org.hibernate.cfg.InheritanceState.getElementsToProcess(InheritanceState.java:224)
    at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:775)
    at org.hibernate.cfg.Configuration$MetadataSourceQueue.processAnnotatedClassesQueue(Configuration.java:3845)
    at org.hibernate.cfg.Configuration$MetadataSourceQueue.processMetadata(Configuration.java:3799)
    at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1412)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1846)
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:857)
    ... 12 more

13:52:38,901 ERROR [org.jboss.as.controller.management-operation] (DeploymentScanner-threads - 2) WFLYCTL0013: Operation ("full-replace-deployment") failed - address: ([]) - failure description: {"WFLYCTL0080: Failed services" => {"jboss.persistenceunit.\"belike.war#conn\"" => "org.jboss.msc.service.StartException in service jboss.persistenceunit.\"belike.war#conn\": javax.persistence.PersistenceException: [PersistenceUnit: conn] Unable to build Hibernate SessionFactory
    Caused by: javax.persistence.PersistenceException: [PersistenceUnit: conn] Unable to build Hibernate SessionFactory
    Caused by: org.hibernate.AnnotationException: No identifier specified for entity: com.rafaelsilverioamaral.belike.entities.PostsEntity"}}
13:52:38,980 INFO  [org.jboss.as.server] (DeploymentScanner-threads - 2) WFLYSRV0016: Replaced deployment "belike.war" with deployment "belike.war"
13:52:38,980 INFO  [org.jboss.as.controller] (DeploymentScanner-threads - 2) WFLYCTL0183: Service status report
WFLYCTL0186:   Services which failed to start:      service jboss.persistenceunit."belike.war#conn": org.jboss.msc.service.StartException in service jboss.persistenceunit."belike.war#conn": javax.persistence.PersistenceException: [PersistenceUnit: conn] Unable to build Hibernate SessionFactory
      service jboss.persistenceunit."belike.war#conn"

主要错误说:

Caused by: org.hibernate.AnnotationException: No identifier specified for entity: com.rafaelsilverioamaral.belike.entities.PostsEntity

但是我不明白为什么会抛出这样的错误,因为post_id已经注明了@Id作为我的实体ID。

0 个答案:

没有答案