org hibernate AnnotationException No identifier specified for entity

org hibernate AnnotationException No identifier specified for entity

While working with Hibernate with Java its very common exception “org hibernate AnnotationException No identifier specified for entity” during application startup. This happens if you model class defined as @entity and column mapping has not been done with matching table attribute and you get exception as below:

Caused by: org.hibernate.AnnotationException: No identifier specified for entity: com.javahonk.model.TestModelWithoutColumnMapping
	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:775)
	at org.hibernate.cfg.Configuration$MetadataSourceQueue.processAnnotatedClassesQueue(Configuration.java:3845)
	at org.hibernate.cfg.Configuration$MetadataSourceQueue.processMetadata(Configuration.java:3799)
	at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1412)
	at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1846)
	at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1930)
	at org.springframework.orm.hibernate4.LocalSessionFactoryBuilder.buildSessionFactory(LocalSessionFactoryBuilder.java:372)
	at org.springframework.orm.hibernate4.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:454)
	at org.springframework.orm.hibernate4.LocalSessionFactoryBean.afterPropertiesSet(LocalSessionFactoryBean.java:439)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1625)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1562)
	... 25 more
  • Solution: To fix this problem you will have to map java class attribute with table column mapping as below based on you table definition:
@Entity
public class TestModelForProcedure {
	
	@Id
	@Column(name="test_id")
	private String test_id;
	
	@Column(name="smID")
	private String smID;
	
	@Column(name="eventDate")
	private java.sql.Date eventDate;
	
	@Column(name="createTime")
	private Date createTime;
	
	@Column(name="updateTime")
	@Temporal(TemporalType.TIMESTAMP)
	private Date updateTime;
        
        //Getter and Setter....
}

 

Reference:

Leave a Reply

Your email address will not be published. Required fields are marked *