如何在Hibernate的import.sql中将表达式分解成更多行? [英] How to break expression into more lines in Hibernate's import.sql?

查看:88
本文介绍了如何在Hibernate的import.sql中将表达式分解成更多行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Hibernate中,可以在类路径的根目录中添加 import.sql 文件,并且在创建Hibernate会话时在该数据库上执行该文件的SQL表达式。

但是,如果某些表达式分成两行或更多行,Hibernate会抛出异常。如何将SQL表达式分解为多行?

解决方案

为了像我这样的人通过搜索找到它:



如果您使用Hibernate4,您可以添加以下属性:

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

到你的hibernate配置(我的是JPA的 persistence.xml )。
用户手册和< a href =https://hibernate.onjira.com/browse/HHH-2403> JIRA问题。



注意 >在Hibernate的 hibernate.cfg.xml 中,规范不能识别属性,并且应该将其作为文本内容提供:

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

(感谢Daniel Gerber指出了这一点)


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)

这篇关于如何在Hibernate的import.sql中将表达式分解成更多行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆