简体   繁体   English

如何在Hibernate的import.sql中将表达式分解为更多行?

[英]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. 在Hibernate中,有可能在classpath的根目录中添加import.sql文件,并且在创建Hibernate会话时,将在数据库上执行此文件中的SQL表达式。

However, Hibernate throws exception if some expression is broken into 2 or more lines. 但是,如果某个表达式被分成2行或更多行,则Hibernate会抛出异常。 How can I break SQL expressions to more lines? 如何将SQL表达式分解为更多行?

For the sake of someone like me finding this through a search: 为了像我这样的人通过搜索找到这个:

If you're using Hibernate4, you can add the following property 如果您使用的是Hibernate4,则可以添加以下属性

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

to your hibernate configuration (mine is JPA's persistence.xml ). 你的hibernate配置(我的是JPA的persistence.xml )。 Compare with the user manual and this JIRA issue . 用户手册和本JIRA问题进行比较

Note that in Hibernate's hibernate.cfg.xml , the specification doesn't recognize the value attribute and you should provide it as text content: 请注意 ,在Hibernate的hibernate.cfg.xml中 ,规范不识别value属性,您应该将其作为文本内容提供:

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

(thanks Daniel Gerber for pointing this out) (感谢Daniel Gerber指出这一点)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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