Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.5k views
in Technique[技术] by (71.8m points)

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

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I had the following

import org.springframework.data.annotation.Id;

Naturally, it should be:

import javax.persistence.Id;

Thanks to @JB Nizet


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...