JPA - PostgreSQL JSONB
JPAλ‘ PostgreSQLμ JSONB 컬λΌμ JSON λ°μ΄ν°λ₯Ό μ²λ¦¬νκ³ μ ν λ Hypersistance Utilsλ₯Ό μ μ©νμ¬ μ½κ² ν΄κ²°ν μ μλ€.
@Type(JsonType.class)
곡μ λ¬Έμμ μ€λͺ λμ΄μλ λλ‘ JsonType κ³Ό JsonBinaryType μ μ¬μ©ν μ μλ€.
@Type(JsonBinaryType.class)
@Column(nullable = false, columnDefinition = "jsonb")
private Map<String, Object> metadata = new HashMap<>();
λ§μ½, 컬λΌμ λν columnDefinitionλ₯Ό μ§μ νμ§ μμΌλ©΄ μλμ κ°μ 맀ν μ€λ₯κ° λ°μν μ μλ€.
Caused by: org.hibernate.MappingException: Unable to determine SQL type name for column 'metadata' of table 'users' because there is no type mapping for org.hibernate.type.SqlTypes code: 1111 (OTHER)
@JdbcTypeCode(SqlTypes.JSON)
JsonType κ³Ό JsonBinaryType λ₯Ό μ¬μ©νλ κ²λ³΄λ€ JdbcTypeCodeμ νμ μ JSON μΌλ‘ μ§μ νλκ² λ κ°λ¨νλ€.
@JdbcTypeCode(SqlTypes.JSON)
private Metadata metadata;
@Data
public class Metadata {
private boolean active;
}
μ맀νμΌλ‘ PostgreSQL μμμ Enum 컬λΌμ λν @JdbcType(PostgreSQLEnumJdbcType::class)λ νμΈν΄λ΄μΌκ² λ€?