Hibernate/JPA “AnnotationException: Unknown Id Generator” is very common exception for database based application development this exception occurred because of @SequenceGenerator for @ID not configured properly.
Problem
Running the following Hibernate’s/Spring Boot JPA annotation sequence generator with PostgreSQL/SQL Server database.
@Id
@Column(name="employee_id", nullable=false)
@GeneratedValue(strategy = GenerationType.SEQUENCE ,generator="employee_id_seq")
private Integer employeeId;
Throw the following Hibernate/JPA Unknown Id.generator exception.
Caused by: org.hibernate.AnnotationException: Unknown Id.generator: employee_id_seq
at org.hibernate.cfg.BinderHelper.makeIdGenerator(BinderHelper.java:413)
at org.hibernate.cfg.AnnotationBinder.bindId(AnnotationBinder.java:1795)
at org.hibernate.cfg.AnnotationBinder.processElementAnnotations(AnnotationBinder.java:1229)
at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:733)
The sequence “employee_user_id_seq” is created in PostgreSQL/SQLServer database, what caused the above “AnnotationException: Unknown Id Generator”?
Solution
When declaring the ID generator startegy in Hibernate’s/JPA, use property with annotation @SequenceGenerator annotation strategy in entity class. Try the above case as following:
@Id
@Column(name="employee_id", nullable=false)
@SequenceGenerator(name="my_seq", sequenceName="employee_id_seq")
@GeneratedValue(strategy = GenerationType.SEQUENCE ,generator="my_seq")
private Integer employeeId;
Related Posts
Your Feedback Motivate Us
If our FacingIssuesOnIT Experts solutions guide you to resolve your issues and improve your knowledge. Please share your comments, like and subscribe to get notifications for our posts.
Happy Learning !!!
You must log in to post a comment.