May
23
2015

org.hibernate.id.Identifier GenerationException: ids for this class must be manually assigned before calling save()

In this post of hibernate we will see one more exception that often occure because some time we forget to specify genration stretagy of primary key column for record in Entity class and neither we give it manually.

Here is simple example of student entity class we are trying to save without specifying genration stretagy of primary column .

Student.java

hibernate.cfg.xml

IdentifierGenerationExceptionClass.java

Here we are not setting up primary key and neither we have specify any genration stretagy in student class. When we will try to run above example then org.hibernate.id.IdentifierGenerationException: ids for this class must be manually assigned before calling save(): exception will be given by hibernate.

We need to modify Student class and add  genration stretagy for primary key genration. We can also overcome from this exception by supplying primary key before saving object.

Modified Class is below

Student.java

This is all in this tutorial. I will get back with almost similar next tutorial.

About the Author: devender kumar

java/j2EE developer

Comments are closed.