Error
org.hibernate.AnnotationException: No identifier specified for entity:
at org.hibernate.cfg.InheritanceState.determineDefaultAccessType(InheritanceState.java:268)
at org.hibernate.cfg.InheritanceState.getElementsToProcess(InheritanceState.java:223)
at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:686)
at org.hibernate.cfg.Configuration$MetadataSourceQueue.processAnnotatedClassesQueue(Configuration.java:4035)
at org.hibernate.cfg.Configuration$MetadataSourceQueue.processMetadata(Configuration.java:3989)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1398)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1856)
Type
Runtime
Cause
There is no Id specified in the entity. Each Hibernate entity needs to be have an id or key ( primary or composite )
Resolution
Specify an element as Id ( With annotation @Id )
If the problem is that the underlying table doesn't have a primary key. Better have a composite key at entity ( make sure that those composite columns are unique at db level too )
@Entity
@Table(name="SAMPLE_TABLE")
@IdClass(SampleEntity.class)
Class SampleEntity implements serializable {
@Id
private String name;
@Id
private String Deptt;
}
or you can have an Id element mapped to ROWID of Table
@Entity
@Table(name="SAMPLE_TABLE")
Class SampleEntity implements serializable {
@Id
@Column(name="ROWID")
private String id;
private String name;
private String Deptt;
}