Alexander Savov (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%...
) *created* an issue
Hibernate ORM (
https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiZDU3YTQ0ZGFi...
) / Bug (
https://hibernate.atlassian.net/browse/HHH-16122?atlOrigin=eyJpIjoiZDU3YT...
) HHH-16122 (
https://hibernate.atlassian.net/browse/HHH-16122?atlOrigin=eyJpIjoiZDU3YT...
) Named type [class xxx] did not implement BasicType nor UserType (
https://hibernate.atlassian.net/browse/HHH-16122?atlOrigin=eyJpIjoiZDU3YT...
)
Issue Type: Bug Affects Versions: 6.1.6 Assignee: Unassigned Components: metamodel
Created: 31/Jan/2023 07:00 AM Environment: - jvm 17
- hibernate 6.1.6
- hypersistence-utils-hibernate-60/3.0.1 used for
io.hypersistence.utils.hibernate.type.json.JsonBinaryType
Priority: Blocker Reporter: Alexander Savov (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%...
)
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* (
https://github.com/type ) system.
The code is changed *from* :
@Type(type = "jsonb")
@Column(columnDefinition = "jsonb")
public ServiceTaskCallback serviceTaskCallback;
*to*
@Type(io.hypersistence.utils.hibernate.type.json.JsonBinaryType.class)
@Column(columnDefinition = "jsonb")
public ServiceTaskCallback serviceTaskCallback;
Similar problem is reported by this stackoverflow (
https://stackoverflow.com/questions/74928307/hibernate-upgrade-to-v6-spri...
) 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) {
// This fails...
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;
// === ! NOTE ! ===
// If this is uncommented and below fragment (which is the SAME) is commented then
it works.
// @Type(JsonBinaryType.class)
// @Column(columnDefinition = "jsonb" )
// public ServiceTaskCallback serviceTaskCallback;
}
@MappedSuperclass
public static class TaskServiceDocument<E extends Enum<E>> extends
MultiTenantDocument {
// === ! NOTE ! ===
// This is the problematic field.
// Same snippet defined above works.
@Type(JsonBinaryType.class)
@Column(columnDefinition = "jsonb" )
public ServiceTaskCallback serviceTaskCallback;
}
// Complains: did not implement BasicType nor UserType
// It worked with Hibernate 5
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:
16:41:00.930 [main] DEBUG org.hibernate.internal.SessionFactoryImpl - Eating error closing
SF on failed attempt to start it
Exception in thread "main" jakarta.persistence.PersistenceException:
[PersistenceUnit: my-persistence-unit] Unable to build Hibernate SessionFactory
at
org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.persistenceException(EntityManagerFactoryBuilderImpl.java:1509)
at
org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:1430)
at
org.hibernate.jpa.HibernatePersistenceProvider.createEntityManagerFactory(HibernatePersistenceProvider.java:55)
at jakarta.persistence.Persistence.createEntityManagerFactory(Persistence.java:80)
at jakarta.persistence.Persistence.createEntityManagerFactory(Persistence.java:55)
at com.example.demo.DemoApplication.main(DemoApplication.java:28)
Caused by: java.lang.IllegalArgumentException: Named type [class
com.example.demo.DemoApplication$ServiceTaskCallback] did not implement BasicType nor
UserType
at org.hibernate.boot.model.TypeDefinition.createResolution(TypeDefinition.java:271)
at org.hibernate.boot.model.TypeDefinition.createResolution(TypeDefinition.java:121)
at org.hibernate.boot.model.TypeDefinition.resolve(TypeDefinition.java:106)
at org.hibernate.mapping.BasicValue.interpretExplicitlyNamedType(BasicValue.java:671)
at org.hibernate.mapping.BasicValue.buildResolution(BasicValue.java:353)
at org.hibernate.mapping.BasicValue.resolve(BasicValue.java:315)
at org.hibernate.mapping.BasicValue.getType(BasicValue.java:293)
at
org.hibernate.metamodel.internal.AttributeFactory.determineAttributeMetadata(AttributeFactory.java:375)
at
org.hibernate.metamodel.internal.AttributeFactory.buildAttribute(AttributeFactory.java:111)
at
org.hibernate.metamodel.internal.AttributeFactory.buildAttribute(AttributeFactory.java:96)
at org.hibernate.metamodel.internal.MetadataContext.wrapUp(MetadataContext.java:331)
at
org.hibernate.metamodel.model.domain.internal.JpaMetamodelImpl.processJpa(JpaMetamodelImpl.java:504)
at
org.hibernate.metamodel.model.domain.internal.MappingMetamodelImpl.finishInitialization(MappingMetamodelImpl.java:244)
at
org.hibernate.metamodel.internal.RuntimeMetamodelsImpl.finishInitialization(RuntimeMetamodelsImpl.java:60)
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:311)
at
org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:415)
at
org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:1425)
... 4 more
(
https://hibernate.atlassian.net/browse/HHH-16122#add-comment?atlOrigin=ey...
) Add Comment (
https://hibernate.atlassian.net/browse/HHH-16122#add-comment?atlOrigin=ey...
)
Get Jira notifications on your phone! Download the Jira Cloud app for Android (
https://play.google.com/store/apps/details?id=com.atlassian.android.jira....
) or iOS (
https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=Em...
) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100214- sha1:9509471 )