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 !!

Comments

Subscribe
Notify of
guest
3 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments

About Us

HowToDoInJava provides tutorials and how-to guides on Java and related technologies.

It also shares the best practices, algorithms & solutions and frequently asked interview questions.

Our Blogs

REST API Tutorial

Dark Mode

Dark Mode