After migration to Hibernate 6 I'm hitting this exception: Unable to build Hibernate SessionFactory; nested exception is java.lang.IllegalArgumentException: Named type [class com.example.demo.DemoApplication$ServiceTaskCallback] did not implement BasicType nor UserType The code change is related to new Hibernate @type system. The code is changed from:
to
Similar problem is reported by this stackoverflow issue. Here's the repro code:
package com.example.demo;
import java.util.*;
import jakarta.persistence.*;
import org.hibernate.annotations.Type;
import io.hypersistence.utils.hibernate.type.json.JsonBinaryType;
public class DemoApplication2 {
public static void main(String[] args) {
Persistence.createEntityManagerFactory("my-persistence-unit");
}
@MappedSuperclass
public static class ServiceDocument {
@Id
public String documentSelfLink;
}
@MappedSuperclass
public static class MultiTenantDocument extends ServiceDocument {
@Type(JsonBinaryType.class)
@Column(columnDefinition = "jsonb")
public List<String> tenantLinks;
}
@MappedSuperclass
public static class TaskServiceDocument<E extends Enum<E>> extends MultiTenantDocument {
@Type(JsonBinaryType.class)
@Column(columnDefinition = "jsonb")
public ServiceTaskCallback serviceTaskCallback;
}
public static class ServiceTaskCallback {
public String serviceSelfLink;
}
@Entity
public static class GenericTaskState extends TaskServiceDocument<GenericTaskState.SubStage> {
public enum SubStage { CREATED }
public String taskId;
}
}
Here’s persistence.xml:
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
version="2.0">
<persistence-unit name="my-persistence-unit">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<properties>
<property name="jakarta.persistence.jdbc.driver" value="org.postgresql.Driver" />
<property name="jakarta.persistence.jdbc.url" value="jdbc:postgresql://localhost:5432/postgres" />
<property name="jakarta.persistence.jdbc.user" value="postgres" />
<property name="jakarta.persistence.jdbc.password" value="password" />
</properties>
</persistence-unit>
</persistence>
And here’s the full stack trace:
|