Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

sql

hibernate

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?

like image 782
amorfis Avatar asked Jan 12 '11 22:01

amorfis


1 Answers

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)

like image 181
mabi Avatar answered Oct 24 '22 08:10

mabi