我有以下配置:
<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; }
但是,在运行时,出现以下异常:
造成原因:org.hibernate.AnnotationException:未为实体指定标识符:org.hibernate.cfg.InheritanceState.determineDefaultAccessType(InheritanceState.java:277)处的com.example.domain.Geoname org.hibernate.cfg.InheritanceState.getElementsToProcess( org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:664)处的InheritanceState.java:224)org.hibernate.cfg.Configuration $ MetadataSourceQueue.processAnnotatedClassesQueue(Configuration.java:3449)处的org.hibernate.cfg.Configuration org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1330)处的org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1730)处的$ MetadataSourceQueue.processMetadata(Configuration.java:3403)
有什么想法吗?
旁注:我在此项目上同时结合了mongodb和hibernate / mysql。
我有以下
import org.springframework.data.annotation.Id;
自然地,它应该是:
import javax.persistence.Id;
感谢@JB Nizet