Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

store strings of arbitrary length in Postgresql

I have a Spring application which uses JPA (Hibernate) initially created with Spring Roo. I need to store Strings with arbitrary length, so for that reason I've annotated the field with @Lob:

public class MyEntity{

    @NotNull
    @Size(min = 2)
    @Lob
    private String message;

    ...
}

The application works ok in localhost but I've deployed it to an external server and it a problem with encoding has appeared. For that reason I'd like to check if the data stored in the PostgreSQL database is ok or not. The application creates/updates the tables automatically. And for that field (message) it has created a column of type:

text NOT NULL

The problem is that after storing data if I browse the table or just do a SELECT of that column I can't see the text but numbers. Those numbers seems to be identifiers to "somewhere" where that information is stored.

Can anyone tell me exactly what are these identifiers and if there is any way of being able to see the stored data in a @Lob columm from a pgAdmin or a select clause?

Is there any better way to store Strings of arbitrary length in JPA?

Thanks.

like image 380
Javi Avatar asked Feb 06 '12 10:02

Javi


People also ask

How do I store large text in PostgreSQL?

Option One: use LOB storage. In relational databases, a particular data type exists to store big amounts of data: LOB (Large OBject). Once we need to store large text in the database, we can start with defining a LOB column. All we need to do is mark the docText attribute with the @Lob annotation.

What is the difference between varchar and text in PostgreSQL?

The only difference between TEXT and VARCHAR(n) is that you can limit the maximum length of a VARCHAR column, for example, VARCHAR(255) does not allow inserting a string more than 255 characters long.


1 Answers

I would recommend skipping the '@Lob' annotation and use columnDefinition like this:

@Column(columnDefinition="TEXT")

see if that helps viewing the data while browsing the database itself.

like image 175
Kris Avatar answered Oct 12 '22 11:10

Kris