Can anybody tell me how to persist long text using JPA (I use PostgreSQL)?
Here's the way I defined a very long string in my class:
@Lob
private String body;
However, this produces a field of type charactervarying(255) in the database.
Furthermore, I've tried to use @Column annotation:
@Column(columnDefinition="TEXT")
private String body;
But everything in vain.
I would be gratefull for a helpfull comment on this problem.
@Column(columnDefinition="TEXT")
is indeed the way to do it. Perhaps you have to regenerate your DDL?
I had the same case today. Just
@Lob
private String body;
should create a db column of typ "text" (PostgreSQL - variable unlimited length) but the table should be regenerated.
This is a very old post, but since it has lots of views, and I had a similar question even today, I guess it's worth a simple answer.
My solution was similar, but I found that I needed the LONGTEXT
column instead:
@Column(columnDefinition="LONGTEXT")
private String body;
And yes, you do have to regenerate it. I'm using Play! and I had to restart my app.
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