org.hibernate.AnnotationException:没有为实体指定标识符 - 即使它是 [英] org.hibernate.AnnotationException: No identifier specified for entity - even when it was

查看:517
本文介绍了org.hibernate.AnnotationException:没有为实体指定标识符 - 即使它是的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下配置:

 < bean id =entityManagerFactory
class =org。 springframework.orm.jpa.LocalContainerEntityManagerFactoryBean>
< property name =dataSourceref =jpaDataSource/>
< property name =jpaVendorAdapter>
< bean class =org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter/>
< / property>
< property name =jpaProperties>
<道具>
< prop key =hibernate.dialect> org.hibernate.dialect.MySQLDialect< / prop>
< prop key =hibernate.show_sql> true< / prop>
< /道具>
< / property>
< property name =packagesToScan>
< list>
<值> com.example.domain< /值>
<值> com.example.repositories< /值>
< / list>
< / property>
< / bean>

我在com.example.domain中有我的Geoname类:

  @Entity 
@Table(name =geonames)
公共类Geoname实现Serializable {

@Id
@Column(name =geonameid)
private Long geonameid = null;
}

但是,当运行时,我收到以下异常:


引起:org.hibernate.AnnotationException:没有指定标识符
为实体:com.example.domain.Geoname为
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:664)
at
org.hibernate.cfg.Configuration $ MetadataSourceQueue.processAnnotatedClassesQueue(Configuration.java:3449)
at
org.hibernate.cfg.Configuration $ MetadataSourceQueue.processMetadata(Configuration.java:3403)
at
org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1330)
at
org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1730)





$ b 注意:我在这个项目中将mongodb和hibernate / mysql结合在一起。

解决方案

我有以下内容:

  import org.springframework.data.annotation。 ID; 

当然,它应该是:

  import javax.persistence.Id; 

感谢@JB Nizet


I have the following configuration:

<bean id="entityManagerFactory"
        class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="dataSource" ref="jpaDataSource" />
        <property name="jpaVendorAdapter">
            <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" />
        </property>
        <property name="jpaProperties">
            <props>
                <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
                <prop key="hibernate.show_sql">true</prop>
            </props>
        </property>
        <property name="packagesToScan">
        <list>
            <value>com.example.domain</value>
            <value>com.example.repositories</value>
        </list>
    </property>
</bean>

I have my Geoname class in com.example.domain:

@Entity
@Table(name="geonames")
public class Geoname implements Serializable {

    @Id
    @Column(name="geonameid")
    private Long geonameid = null;
}

yet, when running, I get the following exception:

Caused by: org.hibernate.AnnotationException: No identifier specified for entity: com.example.domain.Geoname 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:664) at org.hibernate.cfg.Configuration$MetadataSourceQueue.processAnnotatedClassesQueue(Configuration.java:3449) at org.hibernate.cfg.Configuration$MetadataSourceQueue.processMetadata(Configuration.java:3403) at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1330) at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1730)

Any ideas why?

side note: I am combining both mongodb and hibernate/ mysql on this project.

解决方案

I had the following

import org.springframework.data.annotation.Id;

Naturally, it should be:

import javax.persistence.Id;

Thanks to @JB Nizet

这篇关于org.hibernate.AnnotationException:没有为实体指定标识符 - 即使它是的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆