Answer the question
In order to leave comments, you need to log in
Spring: Data truncation: Data too long for column 'page_content' at row 1, why?
I process a text file — "book". Each line of this file will later be a book page (BookPage).
What I do: I create a stream from the file and, filtering out empty lines, convert the stream into a List:
...
stringList = fileLinesStream.filter(l -> !l.isEmpty()).collect(Collectors.toList());
...
for (int i = 0; i < stringList.size(); i++) {
BookPage bookPage = new BookPage(book, stringList.get(i));
bookPageService.CreatePage(bookPage); // в этом методе сервиса вызывается bookPageRepository.save(bookPage);
}
bookPageService.CreatePage(bookPage)
) Spring crashes with the error: @Entity
@Table(name = "pages")
public class BookPage {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "book_id")
private Book book;
@Column(columnDefinition = "LONGBLOB")
private String pageContent;
public BookPage(Book book, String pageContent) {
this.book = book;
this.pageContent = pageContent;
}
public BookPage() {
}
}
Answer the question
In order to leave comments, you need to log in
It looks like the problem was that my changes in the code were not reflected in the database.
Everything was solved simply: I deleted the table, and the next time the application was launched, it was recreated.
Everything works with:
@Column(columnDefinition = "TEXT",
name = "page_content")
private String pageContent;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question