Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JPA and PostqreSQL: long string persistence

Tags:

postgresql

jpa

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.

like image 852
emanemos Avatar asked Dec 09 '09 00:12

emanemos


3 Answers

@Column(columnDefinition="TEXT")

is indeed the way to do it. Perhaps you have to regenerate your DDL?

like image 111
Jonathan Feinberg Avatar answered Sep 28 '22 10:09

Jonathan Feinberg


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.

like image 33
ezgi Avatar answered Sep 28 '22 09:09

ezgi


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.

like image 30
Indigenuity Avatar answered Sep 28 '22 09:09

Indigenuity