我得到这个错误
when executing
my project
and I don't know why.
当执行我的项目时,我不知道为什么。
The goal is to save
Json
text into a database
by using hibernate
.
目标是使用hibernate将Json文本保存到数据库中。
Users.java & UsersBooks.java is likewise,
用户。java & UsersBooks。java是同样的,
Books.java:
Books.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
3 个解决方案
#1
5
You try to save a string value more than 255 chars length. Just increase a column length
尝试保存超过255个字符长度的字符串值。只要增加一列的长度
@Column(name = "xxx", length = 1024)
you need to alter a column length in the database too.
您还需要修改数据库中的列长度。
When you use
当你使用
@Column(name = "xxx")
Hibernate uses a default column length.
Hibernate使用默认的列长度。
You can use @Lob
for a really large text data.
您可以将@Lob用于一个非常大的文本数据。
Please, use xxx_users
in place of tblusers
.
请使用xxx_users代替tblusers。
Use User
in place of Users
.
使用用户代替用户。
Use CascadeType.ALL
on the @OneToMany
part of the association.
使用CascadeType。所有关于协会的@OneToMany部分。
Use a lazy loading on the @ManyToOne
part of the association.
对关联的@ManyToOne部分使用延迟加载。
@ManyToOne(fetch = FetchType.Lazy)
pravate User user;
#2
1
The error message tells that you are trying to store a String which is too large for its destination column (255).
错误消息告诉您正在尝试存储一个字符串,该字符串对于其目标列(255)来说太大。
You can either :
你可以:
- Increase the column size or
- 增加列大小或
- Change the column type to
TEXT
instead ofVARCHAR(255)
. - 将列类型改为文本,而不是VARCHAR(255)。
#3
1
For String with more than 255 chars length you can increase column length :
对于长度超过255字符的字符串,可以增加列长度:
@Column(length = 2048)
private String column;
For large size :
对于大尺寸:
@Lob
private String column;
For unlimited size :
无限的规模:
@Column(columnDefinition="text")
private String column;
#1
5
You try to save a string value more than 255 chars length. Just increase a column length
尝试保存超过255个字符长度的字符串值。只要增加一列的长度
@Column(name = "xxx", length = 1024)
you need to alter a column length in the database too.
您还需要修改数据库中的列长度。
When you use
当你使用
@Column(name = "xxx")
Hibernate uses a default column length.
Hibernate使用默认的列长度。
You can use @Lob
for a really large text data.
您可以将@Lob用于一个非常大的文本数据。
Please, use xxx_users
in place of tblusers
.
请使用xxx_users代替tblusers。
Use User
in place of Users
.
使用用户代替用户。
Use CascadeType.ALL
on the @OneToMany
part of the association.
使用CascadeType。所有关于协会的@OneToMany部分。
Use a lazy loading on the @ManyToOne
part of the association.
对关联的@ManyToOne部分使用延迟加载。
@ManyToOne(fetch = FetchType.Lazy)
pravate User user;
#2
1
The error message tells that you are trying to store a String which is too large for its destination column (255).
错误消息告诉您正在尝试存储一个字符串,该字符串对于其目标列(255)来说太大。
You can either :
你可以:
- Increase the column size or
- 增加列大小或
- Change the column type to
TEXT
instead ofVARCHAR(255)
. - 将列类型改为文本,而不是VARCHAR(255)。
#3
1
For String with more than 255 chars length you can increase column length :
对于长度超过255字符的字符串,可以增加列长度:
@Column(length = 2048)
private String column;
For large size :
对于大尺寸:
@Lob
private String column;
For unlimited size :
无限的规模:
@Column(columnDefinition="text")
private String column;