简体   繁体   中英

How to break expression into more lines in Hibernate's import.sql?

In Hibernate there is possibility to add import.sql file in root of classpath, and the SQL expressions from this file are executed on database when Hibernate session is created.

However, Hibernate throws exception if some expression is broken into 2 or more lines. How can I break SQL expressions to more lines?

For the sake of someone like me finding this through a search:

If you're using Hibernate4, you can add the following property

<property name="hibernate.hbm2ddl.import_files_sql_extractor" value="org.hibernate.tool.hbm2ddl.MultipleLinesSqlCommandExtractor" />

to your hibernate configuration (mine is JPA's persistence.xml ). Compare with the user manual and this JIRA issue .

Note that in Hibernate's hibernate.cfg.xml , the specification doesn't recognize the value attribute and you should provide it as text content:

<property name="hibernate.hbm2ddl.import_files_sql_extractor">org.hibernate.tool.hbm2ddl.MultipleLinesSqlCommandExtractor</property>

(thanks Daniel Gerber for pointing this out)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM