在Postgresql中存储任意长度的字符串 [英] store strings of arbitrary length in Postgresql

查看:2786
本文介绍了在Postgresql中存储任意长度的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Spring应用程序,它使用最初由Spring Roo创建的JPA( Hibernate )。我需要存储任意长度的字符串,因此我已用 @Lob 对字段进行了注释:

  public class MyEntity {

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

...
}

localhost但我已经部署到外部服务器,它出现了编码的问题。因此,我想检查存储在PostgreSQL数据库中的数据是否正确。应用程序自动创建/更新表。对于该字段(消息),它创建了一个类型的列:


text NOT NULL


< blockquote>

问题是,存储数据后,如果我浏览表或只是做一个SELECT的列我看不到文本,但数字。这些数字似乎是存储信息的某处的标识符。



任何人都可以告诉我这些标识符是什么,如果有任何方式能够从pgAdmin或select子句中查看@Lob columm中的存储数据?



有没有更好的方法来存储JPA中任意长度的字符串?



感谢。

解决方案

我建议跳过'@Lob'注释, columnDefinition这样:

  @Column(columnDefinition =TEXT)
pre>

  @Column(columnDefinition =LONGTEXT) 

查看是否有助于在浏览数据库时查看数据。


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.

解决方案

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

@Column(columnDefinition="TEXT")

or

@Column(columnDefinition="LONGTEXT")

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

这篇关于在Postgresql中存储任意长度的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆