我使用 h2 db 和 hibernate 4。
我想从实体自动生成数据库模式并从 import.sql
文件中填充数据库。这是相关的 hibernate.cfg.xml
:
<!-- automatically generate database tables from hibernate entities -->
<property name="hibernate.hbm2ddl.auto">create-drop</property>
<!-- initialize db on startup -->
<property name="hibernate.hbm2ddl.import_files">/import.sql</property>
因此,当生成数据库表时,将调用 import.sql
。这是第一条sql语句:
insert into Borrower values (1,"Greece, Aphines, Square street",5,"Antonio");
当 hibernate 运行这个 sql 语句时它给出一个错误:
квіт 23, 2015 8:56:43 PM org.hibernate.tool.hbm2ddl.SchemaExport importScript
ERROR: HHH000388: Unsuccessful: insert into Borrower values (1,"Greece, Aphines, Square street",5,"Antonio")
квіт 23, 2015 8:56:43 PM org.hibernate.tool.hbm2ddl.SchemaExport importScript
Column "Greece, Aphines, Square street" not found; SQL statement:
insert into Borrower values (1,"Greece, Aphines, Square street",5,"Antonio") [42122-186]
在 insert into
语句中添加列名没有帮助。
这好像是h2数据库的错误。
这个错误是什么意思?
最佳答案
尝试用单引号替换双引号,如下所示:
insert into Borrower values (1,'Greece, Aphines, Square street',5,'Antonio');
关于java - 使用 hibernate.hbm2ddl.import_files 执行 sql 脚本时出错?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29831143/