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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With