Hibernate Error: Unable to locate persister

I encountered this error while I was trying to migrate the hibernate hello world application to hibernate 6.

For migration, I did not make any code changes and only the versions were updated in pom.xml so the error does not make any sense.

1. Problem

The exception in stack trace looks like this when I run the application in Eclipse.

Exception in thread "main" java.lang.IllegalArgumentException: 
  Unable to locate persister: com.howtodoinjava.hibernate.test.dto.EmployeeEntity
  at org.hibernate.internal.SessionImpl.firePersist(SessionImpl.java:735)
  at org.hibernate.internal.SessionImpl.persist(SessionImpl.java:716)
  at com.howtodoinjava.hibernate.test.TestHibernate.main(TestHibernate.java:20)

2. Solution

There are multiple solutions suggested in other blogs/websites but the solution that worked for me was to change the javax.persistence.* annotation to jakarta.persistence.* annotation in the hibernate entity classes.

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import jakarta.persistence.UniqueConstraint;

@Entity
@Table(name = "Employee", uniqueConstraints = {
    @UniqueConstraint(columnNames = "ID"),
    @UniqueConstraint(columnNames = "EMAIL") })
public class EmployeeEntity implements Serializable { 
  
//code
}

The reason is seen in the migration guide that Hibernate version 6.0 moves from Java Persistence as defined by the Java EE specs to Jakarta Persistence as defined by the Jakarta EE spec.

Happy Learning !!

Was this post helpful?

Join 7000+ Awesome Developers

Get the latest updates from industry, awesome resources, blog updates and much more.

* We do not spam !!

Leave a Comment

HowToDoInJava

A blog about Java and related technologies, the best practices, algorithms, and interview questions.