java – 在hibernate中导入import.sql失败
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了java – 在hibernate中导入import.sql失败,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2864字,纯文字阅读大概需要5分钟。
内容图文
![java – 在hibernate中导入import.sql失败](/upload/InfoBanner/zyjiaocheng/907/ab881ff51e184969be607b1131fefd22.jpg)
我希望每次应用程序运行时自动删除表并创建一个新表,并自动插入预定义数据.我已经在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');
注意在关键字之间只留出空格并删除所有不可打印的字符.您可以使用自己喜欢的文本编辑器并使用“显示所有字符”选项.
内容总结
以上是互联网集市为您收集整理的java – 在hibernate中导入import.sql失败全部内容,希望文章能够帮你解决java – 在hibernate中导入import.sql失败所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。