"Unable to instantiate default tuplizer" error when querying data through Hibernate with the JDBC driver for Tablestore

更新时间:
复制 MD 格式

Problem

When querying data through Hibernate with the Java Database Connectivity (JDBC) driver for Tablestore, the following error occurs:

Exception in thread "main" org.hibernate.HibernateException: Unable to instantiate default tuplizer [org.hibernate.tuple.entity.PojoEntityTuplizer]
  at org.hibernate.tuple.entity.EntityTuplizerFactory.constructTuplizer(EntityTuplizerFactory.java:108)
  at org.hibernate.tuple.entity.EntityTuplizerFactory.constructDefaultTuplizer(EntityTuplizerFactory.java:133)
  at org.hibernate.tuple.entity.EntityEntityModeToTuplizerMapping.<init>(EntityEntityModeToTuplizerMapping.java:80)
  at org.hibernate.tuple.entity.EntityMetamodel.<init>(EntityMetamodel.java:322)
  at org.hibernate.persister.entity.AbstractEntityPersister.<init>(AbstractEntityPersister.java:485)
  at org.hibernate.persister.entity.SingleTableEntityPersister.<init>(SingleTableEntityPersister.java:133)
  at org.hibernate.persister.PersisterFactory.createClassPersister(PersisterFactory.java:84)
  at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:286)

Cause

The javassist-x.x.x.jar package is missing from the project classpath.

Hibernate uses javassist for runtime bytecode manipulation to generate dynamic proxies for entity classes. These proxies enable lazy loading and dirty checking. Without javassist on the classpath, Hibernate cannot instantiate PojoEntityTuplizer, and the query fails.

Solution

Add the javassist library to your project. Use Method 1 for Maven projects or Method 2 for non-Maven projects.

Method 1: Add a Maven dependency

Add the following dependency to the <dependencies> block in your pom.xml file. This example uses version 3.15.0-GA.

<!-- https://mvnrepository.com/artifact/org.javassist/javassist -->
<dependency>
    <groupId>org.javassist</groupId>
    <artifactId>javassist</artifactId>
    <version>3.15.0-GA</version>
</dependency>

Method 2: Download and import the JAR manually

  1. Download the javassist-x.x.x.jar file from Maven Repository, where x.x.x is the version number. Choose a version that matches your project requirements.

  2. Import the downloaded JAR into your project.

Verify the fix

After adding the javassist dependency, rebuild your project and re-run the query. The Unable to instantiate default tuplizer error no longer appears.