【问题标题】:Insert into DB via hibernate通过休眠插入数据库
【发布时间】:2013-04-20 12:27:16
【问题描述】:

我已经创建了这个类,它是在我的 postgresql 数据库中创建的:

@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;

我想把它插入到数据库中:

    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");
                   ^

我的查询有什么问题?

【问题讨论】:

    标签: java hibernate postgresql insert


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-12
      相关资源
      最近更新 更多