Spring Hibernate/JPA Postgres:对于类型字符变化来说值太长(255)

Kar*_*hik 0 postgresql hibernate jpa spring-boot

我正在尝试从 Spring Boot、Hibernate/JPA 设置关系,但是在尝试了一整天和今天早上之后,它没有工作。我收到了几个错误,但现在错误仅限于:

org.postgresql.util.PSQLException: ERROR: value too long for type character varying(255)
Run Code Online (Sandbox Code Playgroud)

以下是我的 POJO:

@Entity
public class ParentEvent implements Serializable {

    @Id
    @GeneratedValue
    private long _id;

    @OneToMany(cascade = CascadeType.ALL, mappedBy = "parentEvent")
    private List<ChildEvent> childEvent;

    // other getters and setters
}

@Entity
public class ChildEvent implements Serializable {

    @Id
    @GeneratedValue
    private long id;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name="parentEvent__id")
    private ParentEvent parentEvent;

    // other getters and setters ..
}
Run Code Online (Sandbox Code Playgroud)

我有以下 json 结构:

parentEvent: {
    childEvent: [
        {
            param1: "value",
            param2: "value",
        },
        {
            param1: "value",
            param2: "value",
        },
    ]
}
Run Code Online (Sandbox Code Playgroud)

我已经浏览了几篇 stackoverflow 帖子和教程,上面的结构看起来不错,但我无法让它工作。

我究竟做错了什么?

小智 5

如果您使用 PostgreSQL,则可以使用以下注释:

@Column(columnDefinition="TEXT")
Run Code Online (Sandbox Code Playgroud)

但这不适用于其他数据库。