我创建了这个类,它是在我的 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 接口(interface)手动插入,我也会遇到异常:
FEHLER: Spalte »Type1« existiert nicht
LINE 2: VALUES (0, "Type1" , 5, "String", 1, "room");
^
我的查询有什么问题?
最佳答案
您必须使用单引号传递字符串值。像这样:
INSERT INTO test (id, type, test, test_String, test_1, space)
VALUES (0, 'Type1' , 5, 'String', 1, 'room');
关于java - 通过 hibernate 插入数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16120349/