我正在将 Spring Boot 应用程序从 Java 8 迁移到 Java 21,并将 Spring Boot 2.2 迁移到 3.2。我遇到与已弃用的休眠注释相关的问题。我有一个实体如下
@Getter
@Setter
@Entity
@Table(name = "party_info")
@TypeDefs({ @TypeDef(name = "json", typeClass = JsonStringType.class),
@TypeDef(name = "jsonb", typeClass = JsonBinaryType.class) })
public class PartyInfo implements Serializable {
/**
*
*/
@Serial
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private Long id;
@Column(name = "username", length = 48, unique = true, nullable = false)
private String username;
@Column(name = "update_on")
@Temporal(TemporalType.TIMESTAMP)
private Date updateOn;
@Column(name = "recorded_at")
@Temporal(TemporalType.TIMESTAMP)
private Date recordedAt;
@Type(jsonb.class)
@Column(columnDefinition = "jsonb", name = "party", length = 500)
private PartyResponse partyResponse;
}
这里的问题是找不到TypeDefs和TypeDef,也无法解析jsonb.class。有没有其他方法可以解决这个问题?
您可以使用@Convert将json转换为pojo。如何使用它的示例可以在这里找到:https://www.baeldung.com/spring-boot-jpa-storing-postgresql-jsonb