首页

“org.hibernate.AnnotationException: No identifier specified for entity”问题

标签:java,exception,AnnotationException,BeanCreationException,异常,hibernate,error     发布时间:2015-06-12   

无法启动应用服务,异常日志如下所示:

严重: Exception sending context initialized event to listener instance of@b@@b@ class org.springframework.web.context.ContextLoaderListener@b@org.springframework.beans.factory@b@.BeanCreationException: Error creating bean with name @b@sessionFactory  defined in file [...	@b@argetclassesapplicationContext-conf.xml]: Invocation of init method failed;@b@ nested exception is org.hibernate.@b@ AnnotationException: No identifier specified for entity: com.xx.po.TstPo@b@    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.@b@    initializeBean(AbstractAutowireCapableBeanFactory.java:1482)@b@    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.@b@    doCreateBean(AbstractAutowireCapableBeanFactory.java:521)@b@    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.@b@    createBean(AbstractAutowireCapableBeanFactory.java:458)@b@    at org.springframework.beans.factory.support.@b@    AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)@b@    at org.springframework.beans.factory.support.@b@    DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)@b@    at org.springframework.beans.factory.support.@b@    AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)@b@    at org.springframework.beans.factory.support.@b@    AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)@b@    at org.springframework.beans.factory.support.@b@    DefaultListableBeanFactory@b@    .preInstantiateSingletons(DefaultListableBeanFactory.java:610)@b@    at org.springframework.context.support.@b@    AbstractApplicationContext@b@    .finishBeanFactoryInitialization(AbstractApplicationContext.java:932)@b@    at org.springframework.context.support@b@    .AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)@b@    at org.springframework.web.context.ContextLoader@b@    .configureAndRefreshWebApplicationContext(ContextLoader.java:389)@b@    at org.springframework.web.context.ContextLoader@b@    .initWebApplicationContext(ContextLoader.java:294)@b@    at org.springframework.web.context@b@    .ContextLoaderListener.contextInitialized(ContextLoaderListener.java:112)@b@    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4135)@b@    at org.apache.catalina.core.StandardContext.start(StandardContext.java:4630)@b@    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)@b@    at org.apache.catalina.core.StandardHost.start(StandardHost.java:785)@b@    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)@b@    at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:445)@b@    at org.apache.catalina.startup.Embedded.start(Embedded.java:825)@b@    at org.codehaus.mojo.tomcat.AbstractRunMojo.startContainer(AbstractRunMojo.java:558)@b@    at org.codehaus.mojo.tomcat.AbstractRunMojo.execute(AbstractRunMojo.java:255)@b@    at org.apache.maven.plugin.DefaultBuildPluginManager@b@    .executeMojo(DefaultBuildPluginManager.java:105)@b@    at org.apache.maven.lifecycle.DefaultLifecycleExecutor@b@    .execute(DefaultLifecycleExecutor.java:577)@b@    at org.apache.maven.lifecycle.DefaultLifecycleExecutor@b@    .execute(DefaultLifecycleExecutor.java:324)@b@    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:247)@b@    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:104)@b@    at org.apache.maven.cli.MavenCli.execute(MavenCli.java:427)@b@    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:157)@b@    at org.apache.maven.cli.MavenCli.main(MavenCli.java:121)@b@    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)@b@    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)@b@    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)@b@    at java.lang.reflect.Method.invoke(Method.java:597)@b@    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)@b@    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)@b@    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)@b@    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)@b@Caused by: org.hibernate.AnnotationException: No identifier specified for entity: com.xx.po.TstPo@b@    at org.hibernate.cfg.InheritanceState.determineDefaultAccessType(InheritanceState.java:277)@b@    at org.hibernate.cfg.InheritanceState.getElementsToProcess(InheritanceState.java:224)@b@    at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:665)@b@    at org.hibernate.cfg.Configuration$MetadataSourceQueue@b@    .processAnnotatedClassesQueue(Configuration.java:3533)@b@    at org.hibernate.cfg.Configuration$MetadataSourceQueue@b@    .processMetadata(Configuration.java:3487)@b@    at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1376)@b@    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1777)@b@    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1861)@b@    at org.springframework.orm.hibernate4.LocalSessionFactoryBuilder@b@    .buildSessionFactory(LocalSessionFactoryBuilder.java:247)@b@    at org.springframework.orm.hibernate4.LocalSessionFactoryBean@b@    .buildSessionFactory(LocalSessionFactoryBean.java:373)@b@    at org.springframework.orm.hibernate4.LocalSessionFactoryBean@b@    .afterPropertiesSet(LocalSessionFactoryBean.java:358)@b@    at org.springframework.beans.factory.support@b@    .AbstractAutowireCapableBeanFactory@b@    .invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1541)@b@    at org.springframework.beans.factory.support@b@    .AbstractAutowireCapableBeanFactory@b@    .initializeBean(AbstractAutowireCapableBeanFactory.java:1479)@b@    ... 37 more

原有持久化实体类代码如下:

@Entity@b@@Table(name = "TAB_TSTPO")@b@public class TstPo{@b@    @b@    private static final long serialVersionUID = -1L;@b@    @b@    private name;@b@    private String reMark;@b@   @b@   @b@    @b@    @Column(name="name")@b@    public String getName() {@b@        return name;@b@    }@b@     @b@    public void setReMark(String name) {@b@        this.name = name;@b@    }@b@     @b@    @Column(name="REMARK")@b@    public String getReMark() {@b@        return reMark;@b@    }@b@     @b@    public void setReMark(String reMark) {@b@        this.reMark = reMark;@b@    }@b@    @b@}

解决方法,修改TstPo实体类,配置其主键生成生成方式,具体如下所示:

@Entity@b@@Table(name = "TAB_TSTPO")@b@public class TstPo{@b@    @b@    private static final long serialVersionUID = -1L;@b@    private String id;@b@    private name;@b@    private String reMark;@b@    @b@    @Id@b@    @Indexable(name="id", id=true)@b@    @GeneratedValue(generator = "TstPoGenerator")@b@    @GenericGenerator(name = "TstPoGenerator", strategy = "org.hibernate.id.SequenceGenerator")@b@    public String getId() {@b@        return id;@b@    }@b@@b@    public void setId(String id) {@b@        this.id = id;@b@    } @b@    @b@    @Column(name="name")@b@    public String getName() {@b@        return name;@b@    }@b@     @b@    public void setReMark(String name) {@b@        this.name = name;@b@    }@b@     @b@    @Column(name="REMARK")@b@    public String getReMark() {@b@        return reMark;@b@    }@b@     @b@    public void setReMark(String reMark) {@b@        this.reMark = reMark;@b@    }@b@    @b@}
<<热门下载>>