In this post I want to make a concise investigation regarding one very popular Hibernate exception. Today I will talk about id generating for some table, and if to be more precise, about cases when we need to assign id manually. Let’s start.

Working with data base includes interaction with tables. This circumstance implies existence of different type of references: one to one, many to one, … When the time comes to develop JPA entities not every developer will cope with the task without any problems. The main reason is either lack of theoretical knowledge or attention.

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

The exception above indicates that somewhere in your code you have made an operation with some entity (-ies) and tried to save it (them) without proper id assignment. More often such situation occurs when you are working with some associations. That means you want to add one entity to another and either forget to generate id for one of them or don’t specify the way how Hibernate needs to generate id for entity.

I recommend you see one of the examples when you need to manually set id for your entity.

About The Author

Mathematician, programmer, wrestler, last action hero... Java / Scala architect, trainer, entrepreneur, author of this blog

Close