Thanks Vlad Mihalcea we have such opportunity! )
He created hibernate-types lib:
<dependency>
<groupId>com.vladmihalcea</groupId>
<artifactId>hibernate-types-52</artifactId>
<version>2.1.1</version>
</dependency>
which adds a support of 'json', 'jsonb' and other types to Hibernate:
@Data
@NoArgsConstructor
@Entity
@Table(name = "parents")
@TypeDefs({
@TypeDef(name = "string-array", typeClass = StringArrayType.class),
@TypeDef(name = "int-array", typeClass = IntArrayType.class),
@TypeDef(name = "json", typeClass = JsonStringType.class),
@TypeDef(name = "jsonb", typeClass = JsonBinaryType.class)
})
public class Parent implements Serializable {
@Id
@GeneratedValue(strategy = SEQUENCE)
private Integer id;
@Column(length = 32, nullable = false)
private String name;
@Type(type = "jsonb")
@Column(columnDefinition = "jsonb")
private List<Child> children;
@Type(type = "string-array")
@Column(columnDefinition = "text[]")
private String[] phones;
public Parent(String name, List<Child> children, String... phones) {
this.name = name;
this.children = children;
this.phones = phones;
}
}
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Child implements Serializable {
private String name;
}
More info: 1, 2
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…