[英]Unsuccessful importing import.sql in hibernate
我希望每次應用程序運行時自動刪除表並創建一個新表,並自動插入預定義數據。 我已經在import.sql
准備數據了。 我已經在application.properties
設置了spring.jpa.hibernate.ddl-auto=create-drop
。 但是,為什么我會收到以下錯誤? 我可以手動插入它。
2015-11-20 20:53:57.242 ERROR 7092 --- [ost-startStop-1] org.hibernate.tool.hbm2ddl.SchemaExport : HHH000388: Unsuccessful: INSERT INTO gender
2015-11-20 20:53:57.242 ERROR 7092 --- [ost-startStop-1] org.hibernate.tool.hbm2ddl.SchemaExport : You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
2015-11-20 20:53:57.242 ERROR 7092 --- [ost-startStop-1] org.hibernate.tool.hbm2ddl.SchemaExport : HHH000388: Unsuccessful: (gender_id, gender_name)
2015-11-20 20:53:57.257 ERROR 7092 --- [ost-startStop-1] org.hibernate.tool.hbm2ddl.SchemaExport : You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'gender_id, gender_name)' at line 1
2015-11-20 20:53:57.257 ERROR 7092 --- [ost-startStop-1] org.hibernate.tool.hbm2ddl.SchemaExport : HHH000388: Unsuccessful: VALUES
2015-11-20 20:53:57.257 ERROR 7092 --- [ost-startStop-1] org.hibernate.tool.hbm2ddl.SchemaExport : You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'VALUES' at line 1
2015-11-20 20:53:57.257 ERROR 7092 --- [ost-startStop-1] org.hibernate.tool.hbm2ddl.SchemaExport : HHH000388: Unsuccessful: (1, 'Male'),
2015-11-20 20:53:57.257 ERROR 7092 --- [ost-startStop-1] org.hibernate.tool.hbm2ddl.SchemaExport : You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '1, 'Male'),' at line 1
2015-11-20 20:53:57.257 ERROR 7092 --- [ost-startStop-1] org.hibernate.tool.hbm2ddl.SchemaExport : HHH000388: Unsuccessful: (2, 'Female')
2015-11-20 20:53:57.257 ERROR 7092 --- [ost-startStop-1] org.hibernate.tool.hbm2ddl.SchemaExport : You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '2, 'Female')' at line 1
這是我的實體:
@Entity
public class Gender {
@Id
@Column(name = "gender_id")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;
@Column(name = "gender_name")
private String name;
}
這是我在import.sql
查詢:
INSERT INTO gender
(gender_id, gender_name)
VALUES
(1, 'Male'),
(2, 'Female');
根據錯誤的模式,您的行結尾似乎包含無法處理的字符(隱藏字符,如LF或類似的東西)。
我這樣說是因為你所有的錯誤都與行尾有關。 嘗試將import.sql放在一行中,如下所示:
INSERT INTO gender (gender_id, gender_name) VALUES (1, 'Male'), (2, 'Female');
注意在關鍵字之間只留出空格並刪除所有不可打印的字符。 您可以使用自己喜歡的文本編輯器並使用“顯示所有字符”選項。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.