org.postgresql.util.PSQLException: ERROR: value too long for type charactervariing(255)

当我执行我的项目时,我收到这个错误:enter image description here

目标是使用休眠将文本保存到数据库中。json

Users.java & UsersBooks.java同样,

enter image description here

书籍.java:

@Entity
@Table(name="tblbooks")
public class Books {


@Id
@Column(name = "bookshareId")
private int bookshareId;

@Column(name="author")
private String author;

@Column(name = "availableToDownload")
private int availableToDownload;

@Column(name = "briefSynopsis")
private String briefSynopsis;

@Column(name="category")
private String category;

@Column(name = "completeSynopsis")
private String completeSynopsis;

@Column(name = "contentId")
private int contentId;

@Column(name = "copyright")
private Date copyright;

@Column(name="downloadFormat")
private String downloadFormat;

@Column(name="dtbookSize")
private int dtbookSize;

@Column(name = "freelyAvailable")
private int freelyAvailable;

@Column(name = "brf")
private int brf;

@Column(name = "daisy")
private int daisy;

@Column(name = "images")
private int images;

@Column(name = "isbn13")
private String isbn13;

@Column(name="language")
private String language;

@Column(name = "publishDate")
private Date publishDate;

@Column(name = "publisher")
private String publisher;

@Column(name = "quality")
private String quality;

@Column(name = "title")
private String title;

@OneToMany(mappedBy="book")
private List<UsersBooks> usersBooks;



//Getters & Setters

答案 1

您尝试保存的字符串值的长度超过 255 个字符。只需增加一列长度

@Column(name = "xxx", length = 1024)

您还需要更改数据库中的列长度。

当您使用时

@Column(name = "xxx")

休眠使用默认列长度。

您可以使用非常大的文本数据。@Lob

请代替 使用。xxx_userstblusers

用于代替 。UserUsers

在关联部分使用。CascadeType.ALL@OneToMany

在关联的部分使用延迟加载。@ManyToOne

@ManyToOne(fetch = FetchType.Lazy)
pravate User user;

答案 2

对于长度超过 255 个字符的字符串,您可以增加列长度:

@Column(length = 2048)
private String column;

对于大尺寸 :

@Lob
private String column;

对于无限尺寸:

@Column(columnDefinition="text")
private String column;

推荐