未在类别“ Hello”中定义IdClass

时间:2019-12-15 05:34:00

标签: scala hibernate spring-boot

“我想从Hello类向Hello世界的goldUser获取用户ID的值,但无法获取。获取@Idclass“未为实体指定标识符:”错误。“ / strong>

我在做什么错了,或者应该采取什么方法来从Hello表中获取用户ID的值。

  @Entity
    @Table(name ="Greetings")
    class HelloWorld {

      @Id
      @IdClass(classOf[Hello])
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      @ManyToOne(fetch = FetchType.Lazy)
      @JoinColumn(name = "user_id")
      @BeanProperty
      var goldUser: Hello = _

      @Column(name = "morning")
      @BeanProperty
      var morning: Long = _

      @Column(name = "aftrnoon")
      @BeanProperty
      var afternoon: Long = _

    }"




    "@Entity
    @Table(name = "Hello")
    class Hello {
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      @Column(name = "id")
      @BeanProperty
      var userId: Long = _
    }
"org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'goldEntityManager' defined in class path
     

资源[在/happysellers/webapp/gold/GoldMorningConfig.class中]:   调用init方法失败;嵌套异常为   org.hibernate.AnnotationException:未为实体指定标识符:   in.happysellers.webapp.gold.dotprints.DotPrints         在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1778)   〜[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]         在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:593)   〜[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]         在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515)上   〜[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]         在org.springframework.beans.factory.support.AbstractBeanFactory.lambda $ doGetBean $ 0(AbstractBeanFactory.java:320)   〜[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]         在org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)   〜[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]         在org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318)   〜[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]         在org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)   〜[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]         在org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1105)   〜[spring-context-5.1.6.RELEASE.jar:5.1.6.RELEASE]         在org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:867)   〜[spring-context-5.1.6.RELEASE.jar:5.1.6.RELEASE]         在org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549)   〜[spring-context-5.1.6.RELEASE.jar:5.1.6.RELEASE]         在org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:142)   〜[spring-boot-2.1.4.RELEASE.jar:2.1.4.RELEASE]         在org.springframework.boot.SpringApplication.refresh(SpringApplication.java:775)   〜[spring-boot-2.1.4.RELEASE.jar:2.1.4.RELEASE]         在org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397)   〜[spring-boot-2.1.4.RELEASE.jar:2.1.4.RELEASE]         在org.springframework.boot.SpringApplication.run(SpringApplication.java:316)   〜[spring-boot-2.1.4.RELEASE.jar:2.1.4.RELEASE]       原因:org.hibernate.AnnotationException:未为实体指定标识符:in.happy.webapp.gold.greetingprints.HelloWorld         在org.hibernate.cfg.InheritanceState.getElementsToProcess(InheritanceState.java:231)   〜[hibernate-core-5.3.9.Final.jar:5.3.9.Final]         在org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:775)   〜[hibernate-core-5.3.9.Final.jar:5.3.9.Final]         在org.hibernate.boot.model.source.internal.annotations.AnnotationMetadataSourceProcessorImpl.processEntityHierarchies(AnnotationMetadataSourceProcessorImpl.java:250)处   〜[hibernate-core-5.3.9.Final.jar:5.3.9.Final]         在org.hibernate.boot.model.process.spi.MetadataBuildingProcess $ 1.processEntityHierarchies(MetadataBuildingProcess.java:231)   〜[hibernate-core-5.3.9.Final.jar:5.3.9.Final]         在org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:274)   〜[hibernate-core-5.3.9.Final.jar:5.3.9.Final]         在org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.metadata(EntityManagerFactoryBuilderImpl.java:904)   〜[hibernate-core-5.3.9.Final.jar:5.3.9.Final]         在org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:935)   〜[hibernate-core-5.3.9.Final.jar:5.3.9.Final]         在org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:57)处   〜[spring-orm-5.1.6.RELEASE.jar:5.1.6.RELEASE]         在org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:365)   〜[spring-orm-5.1.6.RELEASE.jar:5.1.6.RELEASE]         在org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:390)   〜[spring-orm-5.1.6.RELEASE.jar:5.1.6.RELEASE]         在org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:377)   〜[spring-orm-5.1.6.RELEASE.jar:5.1.6.RELEASE]         在org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.afterPropertiesSet(LocalContainerEntityManagerFactoryBean.java:341)   〜[spring-orm-5.1.6.RELEASE.jar:5.1.6.RELEASE]         在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1837)   〜[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]         在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1774)   〜[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]         ...省略了21个共同的框架”

1 个答案:

答案 0 :(得分:0)

您需要确保import该课程:

import javax.persistence.IdClass;