通过休眠插入数据库

时间:2013-04-20 12:27:16

标签: java hibernate postgresql insert

我创建了这个在postgresql db中创建的类:

@Entity
public class Test implements Serializable {

    @Id
    @GeneratedValue
    private Long id;

    @NotNull
    @Column(name="type")
    private String type;

    @NotNull
    @Column(name="test")
    private Integer test;

    @NotNull
    @Column(name="test_String")
    private String testString;

    @NotNull
    @Column(name="test_1")
    private Integer test1;

    @NotNull
    @Column(name="space")
    private String space;

我想将其插入db:

    INSERT INTO test (id, type, test, test_String, test_1, space)
VALUES (0, "Type1" , 5, "String", 1, "room");

但是,即使我通过postgresql接口手动插入,我也会遇到异常:

FEHLER:  Spalte »Type1« existiert nicht
LINE 2: VALUES (0, "Type1" , 5, "String", 1, "room");
                   ^

我的查询有什么问题?

1 个答案:

答案 0 :(得分:3)

您必须使用单引号传递字符串值。像这样:

INSERT INTO test (id, type, test, test_String, test_1, space)
VALUES (0, 'Type1' , 5, 'String', 1, 'room');
相关问题