hbm2ddl 无法与 mysql maven spring 休眠 sql 文件一起使用

hbm2ddl not working with mysql maven spring hibernate for sql file

我想用一些数据填充数据库。

我有 sql 脚本。 不管我把 import1.sql 文件放在哪里。

它没有运行,因为我还故意输入了一些错误的语句来确认它是否是导入的。

I already verified the script on the generated schema and it is all fine.

Note: Hibernate configuration like:-

 <prop key="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</prop>
 <prop key="hibernate.show_sql">true</prop>
 <prop key="hibernate.format_sql">true</prop>
 <prop key="hibernate.connection.autocommit">true</prop>
 <prop key="hibernate.hbm2ddl.auto">create</prop>
 <prop key="hibernate.hbm2ddl.import_files">import1.sql</prop>`

               OR

<prop key="hibernate.hbm2ddl.import_files">src/main/resources/scripts/import1.sql</prop>

               OR

<prop key="hibernate.hbm2ddl.import_files">src/main/resources/import1.sql</prop>

               OR

<prop key="hibernate.hbm2ddl.import_files">/import1.sql</prop>

Help me out on this ...

[ 已解决]

Error was multiline comments in the sql file.

src/main/resources/scripts/import1.sql

  • 此处应设置脚本文件夹类路径

  • 以及 java 中的多行注释将不起作用(愚蠢的错误) 并在执行脚本时导致错误。

Things to check:

1) sql File must be direct child of the source folder (i.e in classpath)

2) try to avoid the comments and multi-line statements in sql Script.