有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java如何在pgAdmin3中显示使用Hibernate插入的文本值?

我有一个表,其中有一列“description”,类型为TEXT。如果我这样做:

SELECT id, description FROM table_name;

我在“说明”列中看到的是一个数字,而不是文本值。有没有办法查看文本值

编辑:经过一些测试,我发现了为什么我能看到数字,而像克雷格这样的人却能看到真实的文本。这是因为数据是使用Hibernate插入的

实体:

@Entity public class Settings {

@Id
@GeneratedValue
private Integer id;

@Column(nullable = false, unique = true)
private String key;

@Lob
@Column(nullable = false, length = Integer.MAX_VALUE)
private String value;

//getter和setter

}

日志结果:

Hibernate: create table Settings (id int4 not null, key varchar(255) not null, value text not null, primary key (id));

休眠:选择nextval('Hibernate_sequence') 休眠:插入设置(键、值、id)值(?、、?) 16:05:32718 TRACE BasicBinder:81-将参数[1]绑定为[VARCHAR]-[GoogleSiteVerification] 16:05:32718 TRACE BasicBinder:81-将参数[2]绑定为[CLOB]-[] 16:05:32726 TRACE BasicBinder:81-将参数[3]绑定为[INTEGER]-[4]

如果我在pgAdmin3中执行此操作,请选择:

select * from settings;

我看到这个结果:

1;"GoogleSiteVerification";"112351"


共 (2) 个答案

  1. # 1 楼答案

    设置:

    CREATE TABLE table_name (id integer, description text);
    
    INSERT INTO table_name(id, description) values (1, '12');
    

    演示:

    testdb=> SELECT id, description FROM table_name;
     id | description 
      +      -
      1 | 12
    (1 row)
    

    是的,我想说你的描述列中有一个数字,因为你的描述列中有一个数字

  2. # 2 楼答案

    @Type(type = "org.hibernate.type.TextType")添加到用@Lob注释的属性中。现在它可以按预期工作

    它还解决了编码问题,这也是我首先打开pgAdmin(查看内部内容)的原因

    技术细节:PostgreSQL将LOB存储在单独的位置,并通过数字标识符引用它(这个数字让我感到困惑)