spring-projects / spring-data-jpa

Simplifies the development of creating a JPA-based data access layer.
https://spring.io/projects/spring-data-jpa/
Apache License 2.0
2.93k stars 1.39k forks source link

Unable to determine SQL type name for column 'option_type' of table 'account_options' because there is no type mapping for org.hibernate.type.SqlTypes code: 2000 (JAVA_OBJECT) #3431

Closed rcbandit111 closed 2 months ago

rcbandit111 commented 2 months ago

I have the following code which I want to migrate to Spring Boot 3:

  @Column(name = "OPTION_TYPE")
  @Type(type = "org.hibernate.type.ClassType")
  private Class<T> clazz;

Example demo:

https://github.com/rcbandit111/jpa_class_store_migration_poc/blob/main/src/main/java/com/jpa/store/poc/EnumeratedAccountOption.java

I tried to use:

@Column(name = "OPTION_TYPE")
@JdbcTypeCode(SqlTypes.JAVA_OBJECT)
private Class<T> clazz;
I get this error:

I get error during startup:

Caused by: jakarta.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested exception is org.hibernate.MappingException: Unable to determine SQL type name for column 'option_type' of table 'account_options' because there is no type mapping for org.hibernate.type.SqlTypes code: 2000 (JAVA_OBJECT)
        at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:421) ~[spring-orm-6.1.5.jar!/:6.1.5]
        at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:396) ~[spring-orm-6.1.5.jar!/:6.1.5]
        at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.afterPropertiesSet(LocalContainerEntityManagerFactoryBean.java:366) ~[spring-orm-6.1.5.jar!/:6.1.5]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1833) ~[spring-beans-6.1.5.jar!/:6.1.5]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1782) ~[spring-beans-6.1.5.jar!/:6.1.5]
        ... 92 common frames omitted
Caused by: org.hibernate.MappingException: Unable to determine SQL type name for column 'option_type' of table 'account_options' because there is no type mapping for org.hibernate.type.SqlTypes code: 2000 (JAVA_OBJECT)

Do you know what should be the proper way to implement this?

schauder commented 2 months ago

This is purely a Hibernate mapping problem and therefore off topic here.

I suggest asking on Stackoverflow.