When I execute my project, I get this error:
The goal is to save json
text into a database using hibernate.
Users.java
& UsersBooks.java
is likewise,
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
You try to save a string value more than 255 chars length. Just increase a column length
@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.
You can use @Lob
for a really large text data.
Please, use xxx_users
in place of tblusers
.
Use User
in place of Users
.
Use CascadeType.ALL
on the @OneToMany
part of the association.
Use a lazy loading on the @ManyToOne
part of the association.
@ManyToOne(fetch = FetchType.Lazy)
pravate User user;
For String with more than 255 chars length you can increase column length :
@Column(length = 2048)
private String column;
For large size :
@Lob
private String column;
For unlimited size :
@Column(columnDefinition="text")
private String column;
The error message tells that you are trying to store a String which is too large for its destination column (255).
You can either :
TEXT
instead of VARCHAR(255)
.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With