Framework/Spring Boot

[Error] The propertyClass in JsonTypeDescriptor is null, hence it doesn't know to what Java Object type to map the JSON column value that was read from the database!

잔망루피 2023. 1. 26. 21:04
org.hibernate.HibernateException: The propertyClass in JsonTypeDescriptor is null, hence it doesn't know to what Java Object type to map the JSON column value that was read from the database!

spring.jpa.hibernate.ddl-auto=create로 설정해서 실행하면 테이블이 생성된다.

JSON 필드가 있는 테이블이 잘 생성되길래 문제가 없을 줄 알았는데..

DB에서 읽어올 때 문제가 생김~

 


해결 과정

1. 버전 변경

Hibernate 5.1.2 버전을 사용중이었다.

implementation 'io.hypersistence:hypersistence-utils-hibernate-5:3.1.1'

hypersistence-utils-hibernate는 이렇다.

 

https://github.com/vladmihalcea/hypersistence-utils

이걸 보고 버전을 바꿨다.(공식 문서를 잘 읽자^^)

 

 

2. @TypeDef 어노테이션 추가

버전을 변경하는 것만으로는 해결되지 않았다.

스택오버플로우를 보고 해결방안을 찾았다. 😀

@TypeDef(name = "json", typeClass = JsonType.class)

JSON을 사용하는 해당 클래스 위에 어노테이션 추가

 

 

 

 

참고 👇

https://stackoverflow.com/questions/73331882/serializing-stored-json-object-gives-null-pointer-hibernate-vladmihalcea-hiber

 

Serializing stored json object gives null pointer hibernate vladmihalcea / hibernate-types

I'm saving a java object as json in my db. For this implementation when I save it, it works fine and I can find the new row in my db. However whenever I try to fetch the same object I stored, I get...

stackoverflow.com

https://github.com/vladmihalcea/hypersistence-utils

 

GitHub - vladmihalcea/hypersistence-utils: The Hypersistence Utils library (previously known as Hibernate Types) gives you Sprin

The Hypersistence Utils library (previously known as Hibernate Types) gives you Spring and Hibernate utilities that can help you get the most out of your data access layer. - GitHub - vladmihalcea/...

github.com

 

 

 

 

반응형