본문 바로가기

PROGRAMMING/JPA

[JPA] Blob 컬럼 타입 사용 시 주의할 점

DB : MariaDB

Framework : Spring boot 2.x

 

No serializer found for class java.io.ByteArrayInputStream BLOB

위와 같은 에러 발생

 

직렬화 할수 없다 뭐 이런얘기 같은데

검색해보니 byte로 변환하고 어쩌고 하는 방법이 많이 나왔는데 

간단하게 컬럼 타입이랑 엔티티에서 자료형을 따로 주면 된다.

 

기존

@Column(name = "note_contents")
private Blob contents;

 

변경

@Column(name = "note_contents", columnDefinition = "BLOB")
private byte[] contents;

 

아주 잘 출력되는것을 확인할 수 있다.

 

추가로 CLOB으로 매핑하려면

byte대신 String이나 char[]로 타입을 주면 된다.

 

참조

https://www.baeldung.com/hibernate-lob