Which is the Best Java Web Framework ?

ERROR - Hibernate - org.hibernate.AnnotationException: No identifier specified for entity

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




Subscribe to Java News and Posts. Get latest updates and posts on Java from Buggybread.com
Enter your email address:
Delivered by FeedBurner
comments powered by Disqus




×

Try our new Java Interview Questions Search Tool.

There are more than 1000 questions with practice tests.

It's updated daily and It's Awesome.


×

Try our new Java Practice Test tool.

There are more than 200 questions and expanding quickly. It's updated daily and It's Awesome.