草庐IT

spring - org.hibernate.AnnotationException : No identifier specified for entity - even when it was

coder 2023-05-11 原文

我有以下配置:

<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>

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

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

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

然而,在运行时,我得到以下异常:

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)

有什么想法吗?

旁注:我在这个项目中结合了 mongodb 和 hibernate/mysql。

最佳答案

我有以下

import org.springframework.data.annotation.Id;

自然应该是:

import javax.persistence.Id;

感谢@JB Nizet

关于spring - org.hibernate.AnnotationException : No identifier specified for entity - even when it was,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15320408/

有关spring - org.hibernate.AnnotationException : No identifier specified for entity - even when it was的更多相关文章

随机推荐