Facing could not get constructor for org.hibernate.persister.entity.SingleTableEntityPersister

Hello Everyone, this is my first post on this forum. Hope to be a helpful member of this community.

I am learn spring hibernate currently. I am facing this issue which even after a lot of search I couldn’t find a solution to.
org.hibernate.MappingException: Could not get constructor for org.hibernate.persister.entity.SingleTableEntityPersister

Also asked on stackoverflow but didn’t recieve any response there:

I am not using maven or any such tools, manually including jars.
Hibernate 5 and java 8 used in eclipse. Have already checked for any missing setters/getters and proper imports but couldn’t find any issue.

Student.java

package com.vv.hibernate.demo.entity;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity
@Table(name="student")
public class Student {
	public Student() {
	}
	
	@Id
	@Column(name="id")
	private int id;
	
	@Column(name="first_name")
	private String firstName;
	
	@Column(name="last_name")
	private String lastName;
	
	@Column(name="email")
	private String email;

	public Student(String firstName, String lastName, String email) {
		super();
		this.firstName = firstName;
		this.lastName = lastName;
		this.email = email;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getFirstName() {
		return firstName;
	}

	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}

	public String getLastName() {
		return lastName;
	}

	public void setLastName(String lastName) {
		this.lastName = lastName;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	@Override
	public String toString() {
		return "Student [id=" + id + ", firstName=" + firstName + ", lastName=" + lastName + ", email=" + email + "]";
	}
		
}

CreateStudentDemo.java(main file)

package com.vv.hibernate.demo;

import org.hibernate.MappingException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.boot.Metadata;
import org.hibernate.boot.MetadataSources;
import org.hibernate.boot.registry.StandardServiceRegistry;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import com.vv.hibernate.demo.entity.Student;

public class CreateStudentDemo {

	public static void main(String[] args) throws org.hibernate.MappingException {
		// create session factory
//		SessionFactory factory = new Configuration().configure("hibernate.cfg.xml").addAnnotatedClass(Student.class)
//				.buildSessionFactory();
		SessionFactory sessionFactory;
		try {
			StandardServiceRegistry standardRegistry = new StandardServiceRegistryBuilder()
					.configure("hibernate.cfg.xml").build();
			Metadata metaData = new MetadataSources(standardRegistry)
			.addAnnotatedClass(Student.class)
//			.addAnnotatedClassName( "com.vv.hibernate.demo.entity" )
					.getMetadataBuilder().build();
			sessionFactory = metaData.getSessionFactoryBuilder()
					.build();
		} catch (Exception e) {
			System.out.println("Initial SessionFactory creation failed");
			e.printStackTrace();
			return;
		}

		// create session
//		Session session = sessionFactory.getCurrentSession();

		try(Session session = sessionFactory.openSession()) {
			Student student = new Student("vibhor", "vaish", "v@v.com");
			session.beginTransaction();
			session.save(student);
			session.getTransaction().commit();
			System.out.println("Transaction completed");
			session.close();
		} 
		catch (MappingException exception) {
			System.out.println("Problem creating session factory");
			exception.printStackTrace();
		} 
//		finally {
//			session.close();
//		}

	}

}

hibernate.cf.xml

<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
        "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">

<hibernate-configuration>

    <session-factory>

        <!-- JDBC Database connection settings -->
        <property name="connection.driver_class">com.mysql.cj.jdbc.Driver</property>
        <property name="connection.url">jdbc:mysql://localhost:3306/hb_student_tracker?useSSL=false&amp;serverTimezone=UTC</property>
        <property name="connection.username">hbstudent</property>
        <property name="connection.password">hbstudent</property>

        <!-- JDBC connection pool settings ... using built-in test pool -->
        <property name="connection.pool_size">1</property>

        <!-- Select our SQL dialect -->
        <property name="dialect">org.hibernate.dialect.MySQLDialect</property>

        <!-- Echo the SQL to stdout -->
        <property name="show_sql">true</property>

        <!-- dbcp connection pool configuration 
        <mapping class="com.vv.hibernate.demo.entity.Student" />-->
 
    </session-factory>

</hibernate-configuration>

Console error:

Feb 26, 2021 12:29:22 AM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {5.2.17.Final}
Feb 26, 2021 12:29:22 AM org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by com.sun.xml.bind.v2.runtime.reflect.opt.Injector$1 (file:/C:/eclipseWKSP/hibernate-tutorial/lib/jaxb-impl-2.2.6.jar) to method java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int)
WARNING: Please consider reporting this to the maintainers of com.sun.xml.bind.v2.runtime.reflect.opt.Injector$1
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
Feb 26, 2021 12:29:22 AM org.hibernate.annotations.common.reflection.java.JavaReflectionManager <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
Feb 26, 2021 12:29:23 AM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
WARN: HHH10001002: Using Hibernate built-in connection pool (not for production use!)
Feb 26, 2021 12:29:23 AM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001005: using driver [com.mysql.cj.jdbc.Driver] at URL [jdbc:mysql://localhost:3306/hb_student_tracker?useSSL=false&serverTimezone=UTC]
Feb 26, 2021 12:29:23 AM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001001: Connection properties: {password=****, user=hbstudent}
Feb 26, 2021 12:29:23 AM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001003: Autocommit mode: false
Feb 26, 2021 12:29:23 AM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl$PooledConnections <init>
INFO: HHH000115: Hibernate connection pool size: 1 (min=1)
Feb 26, 2021 12:29:23 AM org.hibernate.dialect.Dialect <init>
INFO: HHH000400: Using dialect: org.hibernate.dialect.MySQLDialect
Feb 26, 2021 12:29:24 AM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl stop
INFO: HHH10001008: Cleaning up connection pool [jdbc:mysql://localhost:3306/hb_student_tracker?useSSL=false&serverTimezone=UTC]
Initial SessionFactory creation failed
org.hibernate.MappingException: Could not get constructor for org.hibernate.persister.entity.SingleTableEntityPersister
	at org.hibernate.persister.internal.PersisterFactoryImpl.createEntityPersister(PersisterFactoryImpl.java:123)
	at org.hibernate.persister.internal.PersisterFactoryImpl.createEntityPersister(PersisterFactoryImpl.java:77)
	at org.hibernate.metamodel.internal.MetamodelImpl.initialize(MetamodelImpl.java:129)
	at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:300)
	at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:462)
	at com.vv.hibernate.demo.CreateStudentDemo.main(CreateStudentDemo.java:27)
Caused by: org.hibernate.HibernateException: Unable to instantiate default tuplizer [org.hibernate.tuple.entity.PojoEntityTuplizer]
	at org.hibernate.tuple.entity.EntityTuplizerFactory.constructTuplizer(EntityTuplizerFactory.java:91)
	at org.hibernate.tuple.entity.EntityTuplizerFactory.constructDefaultTuplizer(EntityTuplizerFactory.java:116)
	at org.hibernate.tuple.entity.EntityMetamodel.<init>(EntityMetamodel.java:382)
	at org.hibernate.persister.entity.AbstractEntityPersister.<init>(AbstractEntityPersister.java:519)
	at org.hibernate.persister.entity.SingleTableEntityPersister.<init>(SingleTableEntityPersister.java:124)
	at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:64)
	at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500)
	at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:481)
	at org.hibernate.persister.internal.PersisterFactoryImpl.createEntityPersister(PersisterFactoryImpl.java:96)
	... 5 more
Caused by: java.lang.reflect.InvocationTargetException
	at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:64)
	at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500)
	at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:481)
	at org.hibernate.tuple.entity.EntityTuplizerFactory.constructTuplizer(EntityTuplizerFactory.java:88)
	... 15 more
Caused by: java.lang.NullPointerException: Cannot invoke "java.lang.reflect.AccessibleObject.setAccessible(boolean)" because "ao" is null
	at javassist.util.proxy.SecurityActions.setAccessible(SecurityActions.java:103)
	at javassist.util.proxy.DefineClassHelper.toClass3(DefineClassHelper.java:151)
	at javassist.util.proxy.DefineClassHelper.toClass2(DefineClassHelper.java:134)
	at javassist.util.proxy.DefineClassHelper.toClass(DefineClassHelper.java:95)
	at javassist.util.proxy.FactoryHelper.toClass(FactoryHelper.java:131)
	at javassist.util.proxy.ProxyFactory.createClass3(ProxyFactory.java:530)
	at javassist.util.proxy.ProxyFactory.createClass2(ProxyFactory.java:515)
	at javassist.util.proxy.ProxyFactory.createClass1(ProxyFactory.java:451)
	at javassist.util.proxy.ProxyFactory.createClass(ProxyFactory.java:422)
	at org.hibernate.proxy.pojo.javassist.JavassistProxyFactory.postInstantiate(JavassistProxyFactory.java:75)
	at org.hibernate.tuple.entity.PojoEntityTuplizer.buildProxyFactory(PojoEntityTuplizer.java:162)
	at org.hibernate.tuple.entity.AbstractEntityTuplizer.<init>(AbstractEntityTuplizer.java:156)
	at org.hibernate.tuple.entity.PojoEntityTuplizer.<init>(PojoEntityTuplizer.java:58)
	... 21 more

Referenced jars

image

Seems you answered your own question already? java - MappingException (Hibernate) - Stack Overflow

Thanks for approving the post.
No, the solution I posted there is , is meant for older and deprecated libraries.
If you notice , old code uses SessionFactory but the current way(proper way) use metadata and standardservice registry. I posted it there since if someone was following the same tutorial, it would help them save a lot of time. I wasted almost 2 days to get the old version working. :sweat_smile:

I still need suggestions for this one.

You seem to be using Java 14 which is definitely not supported by Hibernate 5.2.17

Either you update to the latest Hibernate version or you use a Java 8 runtime.

Nope, as mentioned in the description, both my java and compile version are java 8. In fact, my machine also has 8 only, never updated it.

Look again, I guess this runs with the Java version that is embedded with Eclipse or something like that. The fact that stacktrace frames referring to JDK classes are prefixed with the module name indicates that you run at least on Java 9.

I have tried looking at these places to verify java version but I couldn’t verify
image

Will add other images since I can’t post more than one image in 1 post.

image

I don’t have Eclipse anymore, but beware that Eclipse tells you that the JRE/JDK is “JavaSE-1.8” although what it means to say is that it is “compatible”. It’s still possible that you have configured a newer JRE/JDK for that “profile”. There is some option in Eclipse where you can configure these system libraries which also offers the possibility to configure the exact location of the JRE/JDK.

I was able to set compliance level to 1.8 via window->preferences->java->compiler->set compliance level. It was set to 15. Needed to restart eclipse. Currently working on another project. Will update this one some time later.